class ConditionManager

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Condition/ConditionManager.php \Drupal\Core\Condition\ConditionManager
  2. 10 core/lib/Drupal/Core/Condition/ConditionManager.php \Drupal\Core\Condition\ConditionManager
  3. 8.9.x core/lib/Drupal/Core/Condition/ConditionManager.php \Drupal\Core\Condition\ConditionManager

A plugin manager for condition plugins.

Hierarchy

Expanded class hierarchy of ConditionManager

See also

\Drupal\Core\Condition\Annotation\Condition

\Drupal\Core\Condition\ConditionInterface

\Drupal\Core\Condition\ConditionPluginBase

Related topics

1 file declares its use of ConditionManager
FormController.php in core/modules/system/tests/modules/condition_test/src/FormController.php
1 string reference to 'ConditionManager'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses ConditionManager
plugin.manager.condition in core/core.services.yml
Drupal\Core\Condition\ConditionManager

File

core/lib/Drupal/Core/Condition/ConditionManager.php, line 25

Namespace

Drupal\Core\Condition
View source
class ConditionManager extends DefaultPluginManager implements ExecutableManagerInterface, CategorizingPluginManagerInterface, FilteredPluginManagerInterface {
  use CategorizingPluginManagerTrait;
  use FilteredPluginManagerTrait;
  
  /**
   * Constructs a ConditionManager object.
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
   *   Cache backend instance to use.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to invoke the alter hook with.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
    $this->alterInfo('condition_info');
    $this->setCacheBackend($cache_backend, 'condition_plugins');
    parent::__construct('Plugin/Condition', $namespaces, $module_handler, 'Drupal\\Core\\Condition\\ConditionInterface', 'Drupal\\Core\\Condition\\Annotation\\Condition');
  }
  
  /**
   * {@inheritdoc}
   */
  protected function getType() {
    return 'condition';
  }
  
  /**
   * {@inheritdoc}
   */
  public function createInstance($plugin_id, array $configuration = []) {
    $plugin = $this->getFactory()
      ->createInstance($plugin_id, $configuration);
    // If we receive any context values via config set it into the plugin.
    if (!empty($configuration['context'])) {
      @trigger_error('Passing context values to plugins via configuration is deprecated in drupal:9.1.0 and will be removed before drupal:10.0.0. Instead, call ::setContextValue() on the plugin itself. See https://www.drupal.org/node/3120980', E_USER_DEPRECATED);
      foreach ($configuration['context'] as $name => $context) {
        $plugin->setContextValue($name, $context);
      }
    }
    return $plugin->setExecutableManager($this);
  }
  
  /**
   * {@inheritdoc}
   */
  public function execute(ExecutableInterface $condition) {
    if ($condition instanceof ConditionInterface) {
      $result = $condition->evaluate();
      return $condition->isNegated() ? !$result : $result;
    }
    throw new ExecutableException("This manager object can only execute condition plugins");
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.