You are here

class ConditionPluginCollection in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Condition/ConditionPluginCollection.php \Drupal\Core\Condition\ConditionPluginCollection

Provides a collection of condition plugins.

Hierarchy

Expanded class hierarchy of ConditionPluginCollection

1 file declares its use of ConditionPluginCollection
Block.php in core/modules/block/src/Entity/Block.php
Contains \Drupal\block\Entity\Block.

File

core/lib/Drupal/Core/Condition/ConditionPluginCollection.php, line 16
Contains \Drupal\Core\Condition\ConditionPluginCollection.

Namespace

Drupal\Core\Condition
View source
class ConditionPluginCollection extends DefaultLazyPluginCollection {

  /**
   * An array of collected contexts for conditions.
   *
   * @var \Drupal\Component\Plugin\Context\ContextInterface[]
   */
  protected $conditionContexts = array();

  /**
   * {@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 = array();
      $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

Namesort descending Modifiers Type Description Overrides
ConditionPluginCollection::$conditionContexts protected property An array of collected contexts for conditions.
ConditionPluginCollection::addContext public function Sets the condition context for a given name.
ConditionPluginCollection::get public function Overrides LazyPluginCollection::get
ConditionPluginCollection::getConditionContexts public function Gets the values for all defined contexts.
ConditionPluginCollection::getConfiguration public function Gets the current configuration of all plugins in this collection. Overrides DefaultLazyPluginCollection::getConfiguration
DefaultLazyPluginCollection::$configurations protected property The initial configuration for each plugin in the collection.
DefaultLazyPluginCollection::$manager protected property The manager used to instantiate the plugins.
DefaultLazyPluginCollection::$originalOrder protected property The original order of the instances.
DefaultLazyPluginCollection::$pluginKey protected property The key within the plugin configuration that contains the plugin ID. 3
DefaultLazyPluginCollection::addInstanceId public function Adds an instance ID to the available instance IDs. Overrides LazyPluginCollection::addInstanceId
DefaultLazyPluginCollection::initializePlugin protected function Initializes and stores a plugin. Overrides LazyPluginCollection::initializePlugin 2
DefaultLazyPluginCollection::removeInstanceId public function Removes an instance ID. Overrides LazyPluginCollection::removeInstanceId
DefaultLazyPluginCollection::setConfiguration public function Sets the configuration for all plugins in this collection. Overrides LazyPluginCollection::setConfiguration
DefaultLazyPluginCollection::setInstanceConfiguration public function Updates the configuration for a plugin instance.
DefaultLazyPluginCollection::sort public function Sorts all plugin instances in this collection. 1
DefaultLazyPluginCollection::sortHelper public function Provides uasort() callback to sort plugins. 2
DefaultLazyPluginCollection::__construct public function Constructs a new DefaultLazyPluginCollection object. 1
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
LazyPluginCollection::$instanceIDs protected property Stores the IDs of all potential plugin instances.
LazyPluginCollection::$pluginInstances protected property Stores all instantiated plugins.
LazyPluginCollection::clear public function Clears all instantiated plugins. 1
LazyPluginCollection::count public function
LazyPluginCollection::getInstanceIds public function Gets all instance IDs.
LazyPluginCollection::getIterator public function
LazyPluginCollection::has public function Determines if a plugin instance exists.
LazyPluginCollection::remove public function Removes an initialized plugin. 1
LazyPluginCollection::set public function Stores an initialized plugin.