You are here

final class Generic in Core Context 8

Exposes contexts from various provider services, under a single namespace.

Hierarchy

Expanded class hierarchy of Generic

1 string reference to 'Generic'
core_context.services.yml in ./core_context.services.yml
core_context.services.yml
1 service uses Generic
core_context in ./core_context.services.yml
Drupal\core_context\ContextProvider\Generic

File

src/ContextProvider/Generic.php, line 10

Namespace

Drupal\core_context\ContextProvider
View source
final class Generic implements ContextProviderInterface {

  /**
   * The provider services from which to expose contexts.
   *
   * @var \Drupal\Core\Plugin\Context\ContextProviderInterface[]
   */
  private $providers = [];

  /**
   * Adds a provider service from which to expose contexts.
   *
   * @param \Drupal\Core\Plugin\Context\ContextProviderInterface $provider
   *   The context provider to add.
   */
  public function addProvider(ContextProviderInterface $provider) {
    array_push($this->providers, $provider);
  }

  /**
   * {@inheritdoc}
   */
  public function getRuntimeContexts(array $unqualified_context_ids) {
    $contexts = [];
    foreach ($this->providers as $provider) {
      $contexts = array_merge($contexts, $provider
        ->getRuntimeContexts($unqualified_context_ids));
    }
    return $contexts;
  }

  /**
   * {@inheritdoc}
   */
  public function getAvailableContexts() {
    $contexts = [];
    foreach ($this->providers as $provider) {
      $contexts = array_merge($contexts, $provider
        ->getAvailableContexts());
    }
    return $contexts;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Generic::$providers private property The provider services from which to expose contexts.
Generic::addProvider public function Adds a provider service from which to expose contexts.
Generic::getAvailableContexts public function Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface::getAvailableContexts
Generic::getRuntimeContexts public function Gets runtime context values for the given context IDs. Overrides ContextProviderInterface::getRuntimeContexts