You are here

protected function ContextManager::applyContexts in Context 8

Same name and namespace in other branches
  1. 8.4 src/ContextManager.php \Drupal\context\ContextManager::applyContexts()
  2. 8.0 src/ContextManager.php \Drupal\context\ContextManager::applyContexts()

Apply context to all the context aware conditions in the collection.

Parameters

ConditionPluginCollection $conditions: A collection of conditions to apply context to.

Return value

bool

1 call to ContextManager::applyContexts()
ContextManager::evaluateContextConditions in src/ContextManager.php
Evaluate a contexts conditions.

File

src/ContextManager.php, line 300

Class

ContextManager
This is the manager service for the context module and should not be confused with the built in contexts in Drupal.

Namespace

Drupal\context

Code

protected function applyContexts(ConditionPluginCollection &$conditions) {
  foreach ($conditions as $condition) {
    if ($condition instanceof ContextAwarePluginInterface) {
      try {
        $contexts = $this->contextRepository
          ->getRuntimeContexts(array_values($condition
          ->getContextMapping()));
        $this->contextHandler
          ->applyContextMapping($condition, $contexts);
      } catch (ContextException $e) {
        return FALSE;
      }
    }
  }
  return TRUE;
}