You are here

protected function ContextManager::applyContexts in Context 8.4

Same name and namespace in other branches
  1. 8 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

\Drupal\Core\Condition\ConditionPluginCollection $conditions: A collection of conditions to apply context to.

Return value

bool TRUE if context was applied and FALSE if context is provided but has no value.

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

File

src/ContextManager.php, line 364

Class

ContextManager
This is the manager service for the context module.

Namespace

Drupal\context

Code

protected function applyContexts(ConditionPluginCollection &$conditions) {

  // If no contexts to check, the return should be TRUE.
  // For example, empty is the same as sitewide condition.
  if (count($conditions) === 0) {
    return TRUE;
  }
  $passed = FALSE;
  foreach ($conditions as $condition) {
    if ($condition instanceof ContextAwarePluginInterface) {
      try {
        $contexts = $this->contextRepository
          ->getRuntimeContexts(array_values($condition
          ->getContextMapping()));
        $this->contextHandler
          ->applyContextMapping($condition, $contexts);
        $passed = TRUE;
      } catch (ContextException $e) {
        continue;
      }
    }
  }
  return $passed;
}