3 namespace Drupal\Core\Condition;
5 use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
6 use Drupal\Core\Cache\CacheBackendInterface;
7 use Drupal\Core\Executable\ExecutableManagerInterface;
8 use Drupal\Core\Executable\ExecutableInterface;
9 use Drupal\Core\Extension\ModuleHandlerInterface;
10 use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
11 use Drupal\Core\Plugin\DefaultPluginManager;
12 use Drupal\Core\Plugin\FilteredPluginManagerInterface;
13 use Drupal\Core\Plugin\FilteredPluginManagerTrait;
16 * A plugin manager for condition plugins.
18 * @see \Drupal\Core\Condition\Annotation\Condition
19 * @see \Drupal\Core\Condition\ConditionInterface
20 * @see \Drupal\Core\Condition\ConditionPluginBase
24 class ConditionManager extends DefaultPluginManager implements ExecutableManagerInterface, CategorizingPluginManagerInterface, FilteredPluginManagerInterface {
26 use CategorizingPluginManagerTrait;
27 use FilteredPluginManagerTrait;
30 * Constructs a ConditionManager object.
32 * @param \Traversable $namespaces
33 * An object that implements \Traversable which contains the root paths
34 * keyed by the corresponding namespace to look for plugin implementations.
35 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
36 * Cache backend instance to use.
37 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
38 * The module handler to invoke the alter hook with.
40 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
41 $this->alterInfo('condition_info');
42 $this->setCacheBackend($cache_backend, 'condition_plugins');
44 parent::__construct('Plugin/Condition', $namespaces, $module_handler, 'Drupal\Core\Condition\ConditionInterface', 'Drupal\Core\Condition\Annotation\Condition');
50 protected function getType() {
57 public function createInstance($plugin_id, array $configuration = []) {
58 $plugin = $this->getFactory()->createInstance($plugin_id, $configuration);
60 // If we receive any context values via config set it into the plugin.
61 if (!empty($configuration['context'])) {
62 foreach ($configuration['context'] as $name => $context) {
63 $plugin->setContextValue($name, $context);
67 return $plugin->setExecutableManager($this);
73 public function execute(ExecutableInterface $condition) {
74 $result = $condition->evaluate();
75 return $condition->isNegated() ? !$result : $result;