示例#1
0
  /**
   *
   */
  protected function applyContexts(ConditionPluginCollection &$conditions, $logic) {
    $have_1_testable_condition = FALSE;
    foreach ($conditions as $id => $condition) {
      if ($condition instanceof ContextAwarePluginInterface) {
        try {
          $contexts = $this->contextRepository->getRuntimeContexts(array_values($condition->getContextMapping()));
          $this->contextHandler->applyContextMapping($condition, $contexts);
          $have_1_testable_condition = TRUE;
        }
        catch (ContextException $e) {
          if ($logic == 'and') {
            // Logic is all and found condition with contextException.
            return FALSE;
          }
          $conditions->removeInstanceId($id);

        }

      }
      else {
        $have_1_testable_condition = TRUE;
      }
    }
    if ($logic == 'or' && !$have_1_testable_condition) {
      return FALSE;
    }
    return TRUE;
  }
 /**
  * Sets the condition context for a given name.
  *
  * @param string $name
  *   The name of the context.
  * @param \Drupal\Component\Plugin\Context\ContextInterface $context
  *   The context to add.
  *
  * @return $this
  */
 public function addContext($name, ContextInterface $context)
 {
     $this->conditions->addContext($name, $context);
     return $this;
 }