class ConditionPluginCollection in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Condition/ConditionPluginCollection.php \Drupal\Core\Condition\ConditionPluginCollection
Provides a collection of condition plugins.
Hierarchy
- class \Drupal\Component\Plugin\LazyPluginCollection implements \Drupal\Component\Plugin\Countable, \Drupal\Component\Plugin\IteratorAggregate
- class \Drupal\Core\Plugin\DefaultLazyPluginCollection uses DependencySerializationTrait
- class \Drupal\Core\Condition\ConditionPluginCollection
- class \Drupal\Core\Plugin\DefaultLazyPluginCollection uses DependencySerializationTrait
Expanded class hierarchy of ConditionPluginCollection
1 file declares its use of ConditionPluginCollection
File
- core/
lib/ Drupal/ Core/ Condition/ ConditionPluginCollection.php, line 11
Namespace
Drupal\Core\ConditionView source
class ConditionPluginCollection extends DefaultLazyPluginCollection {
/**
* An array of collected contexts for conditions.
*
* @var \Drupal\Component\Plugin\Context\ContextInterface[]
*/
protected $conditionContexts = [];
/**
* {@inheritdoc}
*
* @return \Drupal\Core\Condition\ConditionInterface
*/
public function &get($instance_id) {
return parent::get($instance_id);
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
$configuration = parent::getConfiguration();
// Remove configuration if it matches the defaults.
foreach ($configuration as $instance_id => $instance_config) {
$default_config = [];
$default_config['id'] = $instance_id;
$default_config += $this
->get($instance_id)
->defaultConfiguration();
// In order to determine if a plugin is configured, we must compare it to
// its default configuration. The default configuration of a plugin does
// not contain context_mapping and it is not used when the plugin is not
// configured, so remove the context_mapping from the instance config to
// compare the remaining values.
unset($instance_config['context_mapping']);
if ($default_config === $instance_config) {
unset($configuration[$instance_id]);
}
}
return $configuration;
}
/**
* Sets the condition context for a given name.
*
* @param string $name
* The name of the context.
* @param \Drupal\Component\Plugin\Context\ContextInterface $context
* The context to add.
*
* @return $this
*/
public function addContext($name, ContextInterface $context) {
$this->conditionContexts[$name] = $context;
return $this;
}
/**
* Gets the values for all defined contexts.
*
* @return \Drupal\Component\Plugin\Context\ContextInterface[]
* An array of set contexts, keyed by context name.
*/
public function getConditionContexts() {
return $this->conditionContexts;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConditionPluginCollection:: |
protected | property | An array of collected contexts for conditions. | |
ConditionPluginCollection:: |
public | function | Sets the condition context for a given name. | |
ConditionPluginCollection:: |
public | function |
Overrides LazyPluginCollection:: |
|
ConditionPluginCollection:: |
public | function | Gets the values for all defined contexts. | |
ConditionPluginCollection:: |
public | function |
Gets the current configuration of all plugins in this collection. Overrides DefaultLazyPluginCollection:: |
|
DefaultLazyPluginCollection:: |
protected | property | The initial configuration for each plugin in the collection. | |
DefaultLazyPluginCollection:: |
protected | property | The manager used to instantiate the plugins. | |
DefaultLazyPluginCollection:: |
protected | property | The original order of the instances. | |
DefaultLazyPluginCollection:: |
protected | property | The key within the plugin configuration that contains the plugin ID. | 3 |
DefaultLazyPluginCollection:: |
public | function |
Adds an instance ID to the available instance IDs. Overrides LazyPluginCollection:: |
|
DefaultLazyPluginCollection:: |
protected | function |
Initializes and stores a plugin. Overrides LazyPluginCollection:: |
2 |
DefaultLazyPluginCollection:: |
public | function |
Removes an instance ID. Overrides LazyPluginCollection:: |
|
DefaultLazyPluginCollection:: |
public | function |
Sets the configuration for all plugins in this collection. Overrides LazyPluginCollection:: |
|
DefaultLazyPluginCollection:: |
public | function | Updates the configuration for a plugin instance. | |
DefaultLazyPluginCollection:: |
public | function | Sorts all plugin instances in this collection. | 1 |
DefaultLazyPluginCollection:: |
public | function | Provides uasort() callback to sort plugins. | 2 |
DefaultLazyPluginCollection:: |
public | function | Constructs a new DefaultLazyPluginCollection object. | 1 |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
LazyPluginCollection:: |
protected | property | Stores the IDs of all potential plugin instances. | |
LazyPluginCollection:: |
protected | property | Stores all instantiated plugins. | |
LazyPluginCollection:: |
public | function | Clears all instantiated plugins. | 1 |
LazyPluginCollection:: |
public | function | ||
LazyPluginCollection:: |
public | function | Gets all instance IDs. | |
LazyPluginCollection:: |
public | function | ||
LazyPluginCollection:: |
public | function | Determines if a plugin instance exists. | |
LazyPluginCollection:: |
public | function | Removes an initialized plugin. | 1 |
LazyPluginCollection:: |
public | function | Stores an initialized plugin. |