Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Condition / ConditionManager.php
1 <?php
2
3 namespace Drupal\Core\Condition;
4
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\Context\ContextAwarePluginManagerTrait;
12 use Drupal\Core\Plugin\DefaultPluginManager;
13
14 /**
15  * A plugin manager for condition plugins.
16  *
17  * @see \Drupal\Core\Condition\Annotation\Condition
18  * @see \Drupal\Core\Condition\ConditionInterface
19  * @see \Drupal\Core\Condition\ConditionPluginBase
20  *
21  * @ingroup plugin_api
22  */
23 class ConditionManager extends DefaultPluginManager implements ExecutableManagerInterface, CategorizingPluginManagerInterface {
24
25   use CategorizingPluginManagerTrait;
26   use ContextAwarePluginManagerTrait;
27
28   /**
29    * Constructs a ConditionManager object.
30    *
31    * @param \Traversable $namespaces
32    *   An object that implements \Traversable which contains the root paths
33    *   keyed by the corresponding namespace to look for plugin implementations.
34    * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
35    *   Cache backend instance to use.
36    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
37    *   The module handler to invoke the alter hook with.
38    */
39   public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
40     $this->alterInfo('condition_info');
41     $this->setCacheBackend($cache_backend, 'condition_plugins');
42
43     parent::__construct('Plugin/Condition', $namespaces, $module_handler, 'Drupal\Core\Condition\ConditionInterface', 'Drupal\Core\Condition\Annotation\Condition');
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function createInstance($plugin_id, array $configuration = []) {
50     $plugin = $this->getFactory()->createInstance($plugin_id, $configuration);
51
52     // If we receive any context values via config set it into the plugin.
53     if (!empty($configuration['context'])) {
54       foreach ($configuration['context'] as $name => $context) {
55         $plugin->setContextValue($name, $context);
56       }
57     }
58
59     return $plugin->setExecutableManager($this);
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function execute(ExecutableInterface $condition) {
66     $result = $condition->evaluate();
67     return $condition->isNegated() ? !$result : $result;
68   }
69
70 }