Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[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\DefaultPluginManager;
12 use Drupal\Core\Plugin\FilteredPluginManagerInterface;
13 use Drupal\Core\Plugin\FilteredPluginManagerTrait;
14
15 /**
16  * A plugin manager for condition plugins.
17  *
18  * @see \Drupal\Core\Condition\Annotation\Condition
19  * @see \Drupal\Core\Condition\ConditionInterface
20  * @see \Drupal\Core\Condition\ConditionPluginBase
21  *
22  * @ingroup plugin_api
23  */
24 class ConditionManager extends DefaultPluginManager implements ExecutableManagerInterface, CategorizingPluginManagerInterface, FilteredPluginManagerInterface {
25
26   use CategorizingPluginManagerTrait;
27   use FilteredPluginManagerTrait;
28
29   /**
30    * Constructs a ConditionManager object.
31    *
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.
39    */
40   public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
41     $this->alterInfo('condition_info');
42     $this->setCacheBackend($cache_backend, 'condition_plugins');
43
44     parent::__construct('Plugin/Condition', $namespaces, $module_handler, 'Drupal\Core\Condition\ConditionInterface', 'Drupal\Core\Condition\Annotation\Condition');
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   protected function getType() {
51     return 'condition';
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function createInstance($plugin_id, array $configuration = []) {
58     $plugin = $this->getFactory()->createInstance($plugin_id, $configuration);
59
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);
64       }
65     }
66
67     return $plugin->setExecutableManager($this);
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function execute(ExecutableInterface $condition) {
74     $result = $condition->evaluate();
75     return $condition->isNegated() ? !$result : $result;
76   }
77
78 }