Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / lib / Drupal / Core / Condition / ConditionPluginCollection.php
1 <?php
2
3 namespace Drupal\Core\Condition;
4
5 use Drupal\Component\Plugin\Context\ContextInterface;
6 use Drupal\Core\Plugin\DefaultLazyPluginCollection;
7
8 /**
9  * Provides a collection of condition plugins.
10  */
11 class ConditionPluginCollection extends DefaultLazyPluginCollection {
12
13   /**
14    * An array of collected contexts for conditions.
15    *
16    * @var \Drupal\Component\Plugin\Context\ContextInterface[]
17    */
18   protected $conditionContexts = [];
19
20   /**
21    * {@inheritdoc}
22    *
23    * @return \Drupal\Core\Condition\ConditionInterface
24    */
25   public function &get($instance_id) {
26     return parent::get($instance_id);
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function getConfiguration() {
33     $configuration = parent::getConfiguration();
34     // Remove configuration if it matches the defaults.
35     foreach ($configuration as $instance_id => $instance_config) {
36       $default_config = [];
37       $default_config['id'] = $instance_id;
38       $default_config += $this->get($instance_id)->defaultConfiguration();
39       // In order to determine if a plugin is configured, we must compare it to
40       // its default configuration. The default configuration of a plugin does
41       // not contain context_mapping and it is not used when the plugin is not
42       // configured, so remove the context_mapping from the instance config to
43       // compare the remaining values.
44       unset($instance_config['context_mapping']);
45       if ($default_config === $instance_config) {
46         unset($configuration[$instance_id]);
47       }
48     }
49     return $configuration;
50   }
51
52   /**
53    * Sets the condition context for a given name.
54    *
55    * @param string $name
56    *   The name of the context.
57    * @param \Drupal\Component\Plugin\Context\ContextInterface $context
58    *   The context to add.
59    *
60    * @return $this
61    */
62   public function addContext($name, ContextInterface $context) {
63     $this->conditionContexts[$name] = $context;
64     return $this;
65   }
66
67   /**
68    * Gets the values for all defined contexts.
69    *
70    * @return \Drupal\Component\Plugin\Context\ContextInterface[]
71    *   An array of set contexts, keyed by context name.
72    */
73   public function getConditionContexts() {
74     return $this->conditionContexts;
75   }
76
77 }