Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ConditionPluginBase.php

class ConditionPluginBase

Provides a basis for fulfilling contexts for condition plugins.

Hierarchy

  • class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
    • class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
      • class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
        • class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait

Expanded class hierarchy of ConditionPluginBase

See also

\Drupal\Core\Condition\Annotation\Condition

\Drupal\Core\Condition\Attribute\Condition

\Drupal\Core\Condition\ConditionInterface

\Drupal\Core\Condition\ConditionManager

Related topics

Plugin API
Using the Plugin API
6 files declare their use of ConditionPluginBase
CurrentThemeCondition.php in core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
EntityBundle.php in core/lib/Drupal/Core/Entity/Plugin/Condition/EntityBundle.php
Language.php in core/modules/language/src/Plugin/Condition/Language.php
RequestPath.php in core/modules/system/src/Plugin/Condition/RequestPath.php
ResponseStatus.php in core/modules/system/src/Plugin/Condition/ResponseStatus.php

... See full list

File

core/lib/Drupal/Core/Condition/ConditionPluginBase.php, line 21

Namespace

Drupal\Core\Condition
View source
abstract class ConditionPluginBase extends ExecutablePluginBase implements ConditionInterface {
    use ContextAwarePluginAssignmentTrait;
    
    /**
     * The condition manager to proxy execute calls through.
     *
     * @var \Drupal\Core\Executable\ExecutableManagerInterface
     */
    protected $executableManager;
    
    /**
     * {@inheritdoc}
     */
    public function __construct(array $configuration, $plugin_id, $plugin_definition) {
        parent::__construct($configuration, $plugin_id, $plugin_definition);
        $this->setConfiguration($configuration);
    }
    
    /**
     * {@inheritdoc}
     */
    public function isNegated() {
        return !empty($this->configuration['negate']);
    }
    
    /**
     * {@inheritdoc}
     */
    public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
        if ($form_state instanceof SubformStateInterface) {
            $form_state = $form_state->getCompleteFormState();
        }
        $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
        $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts);
        $form['negate'] = [
            '#type' => 'checkbox',
            '#title' => $this->t('Negate the condition'),
            '#default_value' => $this->configuration['negate'],
        ];
        return $form;
    }
    
    /**
     * {@inheritdoc}
     */
    public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    }
    
    /**
     * {@inheritdoc}
     */
    public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
        $this->configuration['negate'] = $form_state->getValue('negate');
        if ($form_state->hasValue('context_mapping')) {
            $this->setContextMapping($form_state->getValue('context_mapping'));
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function execute() {
        return $this->executableManager
            ->execute($this);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getConfiguration() {
        return [
            'id' => $this->getPluginId(),
        ] + $this->configuration;
    }
    
    /**
     * {@inheritdoc}
     */
    public function setConfiguration(array $configuration) {
        $this->configuration = $configuration + $this->defaultConfiguration();
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function defaultConfiguration() {
        return [
            'negate' => FALSE,
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function calculateDependencies() {
        return [];
    }
    
    /**
     * {@inheritdoc}
     */
    public function setExecutableManager(ExecutableManagerInterface $executableManager) {
        $this->executableManager = $executableManager;
        return $this;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ConditionInterface::evaluate public function Evaluates the condition and returns TRUE or FALSE accordingly. 6
ConditionInterface::summary public function Provides a human readable summary of the condition's configuration. 6
ConditionPluginBase::$executableManager protected property The condition manager to proxy execute calls through.
ConditionPluginBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 6
ConditionPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
ConditionPluginBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 6
ConditionPluginBase::execute public function Executes the plugin. Overrides ExecutableInterface::execute
ConditionPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ConditionPluginBase::isNegated public function Determines whether condition result will be negated. Overrides ConditionInterface::isNegated 1
ConditionPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ConditionPluginBase::setExecutableManager public function Sets the executable manager class. Overrides ConditionInterface::setExecutableManager
ConditionPluginBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 6
ConditionPluginBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 1
ConditionPluginBase::__construct public function 4
ContextAwarePluginAssignmentTrait::addContextAssignmentElement protected function Builds a form element for assigning a context to a given slot.
ContextAwarePluginAssignmentTrait::contextHandler protected function Wraps the context handler.
ContextAwarePluginAssignmentTrait::t abstract protected function Ensures the t() method is available.
ContextAwarePluginTrait::$context protected property The data objects representing the context of this plugin.
ContextAwarePluginTrait::getCacheContexts public function 7
ContextAwarePluginTrait::getCacheMaxAge public function 2
ContextAwarePluginTrait::getCacheTags public function 2
ContextAwarePluginTrait::getContext public function
ContextAwarePluginTrait::getContextDefinition public function
ContextAwarePluginTrait::getContextDefinitions public function
ContextAwarePluginTrait::getContextMapping public function 1
ContextAwarePluginTrait::getContexts public function
ContextAwarePluginTrait::getContextValue public function
ContextAwarePluginTrait::getContextValues public function
ContextAwarePluginTrait::getPluginDefinition abstract public function 1
ContextAwarePluginTrait::setContext public function 1
ContextAwarePluginTrait::setContextMapping public function
ContextAwarePluginTrait::setContextValue public function
ContextAwarePluginTrait::validateContexts public function
ExecutablePluginBase::getConfig public function Gets all configuration values.
ExecutablePluginBase::getConfigDefinition public function Gets the definition of a configuration option.
ExecutablePluginBase::getConfigDefinitions public function Gets an array of definitions of available configuration options.
ExecutablePluginBase::setConfig public function Sets the value of a particular configuration option.
PluginInspectionInterface::getPluginId public function Gets the plugin ID of the plugin instance. 2
RSS feed
Powered by Drupal