class ConfigContext

Defines the base configuration context object.

A configuration context object provides a data array that can be used as parameters to get customized configuration objects.

Hierarchy

Expanded class hierarchy of ConfigContext

3 files declare their use of ConfigContext
LocaleConfigSubscriber.php in drupal/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php
Contains \Drupal\locale\LocaleConfigSubscriber.
SystemConfigSubscriber.php in drupal/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php
Contains \Drupal\system\SystemConfigSubscriber.
UserConfigContext.php in drupal/core/modules/user/lib/Drupal/user/UserConfigContext.php
Contains \Drupal\user\UserConfigContext.

File

drupal/core/lib/Drupal/Core/Config/Context/ConfigContext.php, line 22
Contains \Drupal\Core\Config\Context\ConfigContext.

Namespace

Drupal\Core\Config\Context
View source
class ConfigContext implements ContextInterface {

  /**
   * The actual storage of key-value pairs.
   *
   * @var array
   */
  protected $data = array();

  /**
   * Any config overrides of key-value pairs.
   *
   * @var array
   */
  protected $overrides = array();

  /**
   * An event dispatcher instance to use for configuration events.
   *
   * @var \Symfony\Component\EventDispatcher\EventDispatcher
   */
  protected $eventDispatcher;

  /**
   * A unique identifier for the context.
   *
   * @var string
   */
  protected $uuid;

  /**
   * Constructs the configuration context.
   *
   * @param \Symfony\Component\EventDispatcher\EventDispatcher $event_dispatcher
   *   An event dispatcher instance to use for configuration events.
   */
  public function __construct(EventDispatcher $event_dispatcher) {
    $this->eventDispatcher = $event_dispatcher;
  }

  /**
   * Implements \Drupal\Core\Config\Context\ContextInterface::init().
   */
  public function init() {

    // Reset existing overrides and get a UUID for this context.
    $this->overrides = array();
    $this
      ->setUuid();

    // Notify event listeners that a configuration context has been created.
    $this
      ->notify('context', NULL);
    return $this;
  }

  /**
   * Implements \Drupal\Core\Config\Context\ContextInterface::get().
   */
  public function get($key) {
    return array_key_exists($key, $this->data) ? $this->data[$key] : NULL;
  }

  /**
   * Implements \Drupal\Core\Config\Context\ContextInterface::set().
   */
  public function set($key, $value) {
    $this->data[$key] = $value;
  }

  /**
   * Implements \Drupal\Core\Config\Context\ContextInterface::setUuid().
   */
  public function setUuid() {
    $uuid = new Uuid();
    $this->uuid = $uuid
      ->generate();
  }

  /**
   * Implements \Drupal\Core\Config\Context\ContextInterface::getUuid().
   */
  public function getUuid() {
    return $this->uuid;
  }

  /**
   * Implements \Drupal\Core\Config\Context\ContextInterface::notify().
   */
  public function notify($config_event_name, Config $config = NULL) {
    $this->eventDispatcher
      ->dispatch('config.' . $config_event_name, new ConfigEvent($this, $config));
  }

  /**
   * Implements \Drupal\Core\Config\Context\ContextInterface::setOverride().
   */
  public function setOverrides($config_name, $data) {
    if (!isset($this->overrides[$config_name])) {
      $this->overrides[$config_name] = $data;
    }
    else {
      $this->overrides[$config_name] = NestedArray::mergeDeepArray(array(
        $this->overrides[$config_name],
        $data,
      ), TRUE);
    }
  }

  /**
   * Implements \Drupal\Core\Config\Context\ContextInterface::getOverrides().
   */
  public function getOverrides($config_name) {
    if (isset($this->overrides[$config_name])) {
      return $this->overrides[$config_name];
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigContext::$data protected property The actual storage of key-value pairs.
ConfigContext::$eventDispatcher protected property An event dispatcher instance to use for configuration events.
ConfigContext::$overrides protected property Any config overrides of key-value pairs.
ConfigContext::$uuid protected property A unique identifier for the context.
ConfigContext::get public function Implements \Drupal\Core\Config\Context\ContextInterface::get(). Overrides ContextInterface::get
ConfigContext::getOverrides public function Implements \Drupal\Core\Config\Context\ContextInterface::getOverrides(). Overrides ContextInterface::getOverrides 1
ConfigContext::getUuid public function Implements \Drupal\Core\Config\Context\ContextInterface::getUuid(). Overrides ContextInterface::getUuid
ConfigContext::init public function Implements \Drupal\Core\Config\Context\ContextInterface::init(). Overrides ContextInterface::init
ConfigContext::notify public function Implements \Drupal\Core\Config\Context\ContextInterface::notify(). Overrides ContextInterface::notify
ConfigContext::set public function Implements \Drupal\Core\Config\Context\ContextInterface::set(). Overrides ContextInterface::set
ConfigContext::setOverrides public function Implements \Drupal\Core\Config\Context\ContextInterface::setOverride(). Overrides ContextInterface::setOverrides 1
ConfigContext::setUuid public function Implements \Drupal\Core\Config\Context\ContextInterface::setUuid(). Overrides ContextInterface::setUuid
ConfigContext::__construct public function Constructs the configuration context.