diff --git a/core/modules/views/src/Plugin/Derivative/ViewsBlock.php b/core/modules/views/src/Plugin/Derivative/ViewsBlock.php index 909b682..3ba84e5 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsBlock.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsBlock.php @@ -6,6 +6,7 @@ use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\views\Plugin\views\ArgumentContextProviderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -114,21 +115,8 @@ public function getDerivativeDefinitions($base_plugin_definition) { // Look for arguments and expose them as context. foreach ($display->getHandlers('argument') as $argument_name => $argument) { - /** @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase $argument */ - if (($validator = $argument->getPlugin('argument_validator')) && $validator->getPluginId() != 'none') { - /** @var \Drupal\views\Plugin\views\argument_validator\ArgumentValidatorPluginBase $validator */ - if (strpos($validator->getPluginId(), 'entity:') !== FALSE) { - $this->derivatives[$delta]['context'][$argument_name] = new ContextDefinition($argument->getPlugin('argument_validator')->getPluginId(), $argument->adminLabel(), FALSE); - } - elseif ($validator->getPluginId() == 'numeric') { - $this->derivatives[$delta]['context'][$argument_name] = new ContextDefinition('integer', $argument->adminLabel(), FALSE); - } - } - else { - switch ($argument->getPluginId()) { - case 'numeric': - $this->derivatives[$delta]['context'][$argument_name] = new ContextDefinition('integer', $argument->adminLabel(), FALSE); - } + if ($argument instanceof ArgumentContextProviderInterface && $context_definition = $argument->getContextDefinition()) { + $this->derivatives[$delta]['context'][$argument_name] = $context_definition; } } diff --git a/core/modules/views/src/Plugin/views/ArgumentContextProviderInterface.php b/core/modules/views/src/Plugin/views/ArgumentContextProviderInterface.php new file mode 100644 index 0000000..977678d --- /dev/null +++ b/core/modules/views/src/Plugin/views/ArgumentContextProviderInterface.php @@ -0,0 +1,19 @@ +getPlugin('argument_validator') instanceof ArgumentContextProviderInterface) { + return $this->getPlugin('argument_validator')->getContextDefinition(); + } + } + } /** diff --git a/core/modules/views/src/Plugin/views/argument/NumericArgument.php b/core/modules/views/src/Plugin/views/argument/NumericArgument.php index b314836..c2a8293 100644 --- a/core/modules/views/src/Plugin/views/argument/NumericArgument.php +++ b/core/modules/views/src/Plugin/views/argument/NumericArgument.php @@ -3,6 +3,7 @@ namespace Drupal\views\Plugin\views\argument; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Plugin\Context\ContextDefinition; /** * Basic argument handler for arguments that are numeric. Incorporates @@ -124,4 +125,17 @@ public function getSortName() { return $this->t('Numerical', array(), array('context' => 'Sort order')); } + /** + * {@inheritdoc} + */ + public function getContextDefinition() { + if ($context_definition = parent::getContextDefinition()) { + return $context_definition; + } + + // If the parent does not provide a context definition through the + // validation plugin, fall back to the integer type. + return new ContextDefinition('integer', $this->adminLabel(), FALSE); + } + } diff --git a/core/modules/views/src/Plugin/views/argument_validator/Entity.php b/core/modules/views/src/Plugin/views/argument_validator/Entity.php index 53e29d7..60eb51c 100644 --- a/core/modules/views/src/Plugin/views/argument_validator/Entity.php +++ b/core/modules/views/src/Plugin/views/argument_validator/Entity.php @@ -5,7 +5,9 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\views\Plugin\views\argument\ArgumentPluginBase; +use Drupal\views\Plugin\views\ArgumentContextProviderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -18,7 +20,7 @@ * * @see \Drupal\views\Plugin\Derivative\ViewsEntityArgumentValidator */ -class Entity extends ArgumentValidatorPluginBase { +class Entity extends ArgumentValidatorPluginBase implements ArgumentContextProviderInterface { /** * The entity manager. @@ -228,4 +230,13 @@ public function calculateDependencies() { return $dependencies; } + /** + * {@inheritdoc} + */ + public function getContextDefinition() { + // The plugin ID is entity:, which is the same as the typed + // data type for entity types. + return new ContextDefinition($this->getPluginId(), $this->argument->adminLabel(), FALSE); + } + } diff --git a/core/modules/views/src/Plugin/views/argument_validator/NumericArgumentValidator.php b/core/modules/views/src/Plugin/views/argument_validator/NumericArgumentValidator.php index a3184f4..90928c5 100644 --- a/core/modules/views/src/Plugin/views/argument_validator/NumericArgumentValidator.php +++ b/core/modules/views/src/Plugin/views/argument_validator/NumericArgumentValidator.php @@ -2,6 +2,9 @@ namespace Drupal\views\Plugin\views\argument_validator; +use Drupal\Core\Plugin\Context\ContextDefinition; +use Drupal\views\Plugin\views\ArgumentContextProviderInterface; + /** * Validate whether an argument is numeric or not. * @@ -12,10 +15,17 @@ * title = @Translation("Numeric") * ) */ -class NumericArgumentValidator extends ArgumentValidatorPluginBase { +class NumericArgumentValidator extends ArgumentValidatorPluginBase implements ArgumentContextProviderInterface { public function validateArgument($argument) { return is_numeric($argument); } + /** + * {@inheritdoc} + */ + public function getContextDefinition() { + return new ContextDefinition('integer', $this->argument->adminLabel(), FALSE); + } + }