function ContextHandler::getMatchingContexts

Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Plugin/Context/ContextHandler.php \Drupal\Core\Plugin\Context\ContextHandler::getMatchingContexts()
  2. 10 core/lib/Drupal/Core/Plugin/Context/ContextHandler.php \Drupal\Core\Plugin\Context\ContextHandler::getMatchingContexts()
  3. 11.x core/lib/Drupal/Core/Plugin/Context/ContextHandler.php \Drupal\Core\Plugin\Context\ContextHandler::getMatchingContexts()

Determines which contexts satisfy the constraints of a given definition.

@todo Use context definition objects after https://www.drupal.org/node/2281635.

Parameters

\Drupal\Component\Plugin\Context\ContextInterface[] $contexts: An array of contexts.

\Drupal\Core\Plugin\Context\ContextDefinitionInterface $definition: The definition to satisfy.

Return value

\Drupal\Component\Plugin\Context\ContextInterface[] An array of matching contexts.

Overrides ContextHandlerInterface::getMatchingContexts

1 call to ContextHandler::getMatchingContexts()
ContextHandler::checkRequirements in core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
Checks a set of requirements against a set of contexts.

File

core/lib/Drupal/Core/Plugin/Context/ContextHandler.php, line 74

Class

ContextHandler
Provides methods to handle sets of contexts.

Namespace

Drupal\Core\Plugin\Context

Code

public function getMatchingContexts(array $contexts, ContextDefinitionInterface $definition) {
    return array_filter($contexts, function (ContextInterface $context) use ($definition) {
        return $definition->isSatisfiedBy($context);
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.