You are here

public function TawkToConditionPluginsHandler::getConditions in Tawk.to - Live chat application (Drupal 8) 8

Same name and namespace in other branches
  1. 8.2 src/Service/TawkToConditionPluginsHandler.php \Drupal\tawk_to\Service\TawkToConditionPluginsHandler::getConditions()

Gets condition plugins based on the module configuration.

Return value

\Drupal\Core\Condition\ConditionInterface[] A set of conditions.

1 call to TawkToConditionPluginsHandler::getConditions()
TawkToConditionPluginsHandler::checkAccess in src/Service/TawkToConditionPluginsHandler.php

File

src/Service/TawkToConditionPluginsHandler.php, line 85

Class

TawkToConditionPluginsHandler
Defines the condition plugins handler.

Namespace

Drupal\tawk_to\Service

Code

public function getConditions() {
  $conditions = [];
  foreach ($this->tawkToVisibility as $conditionId => $configuration) {
    $condition = $this->manager
      ->createInstance($conditionId, $configuration);
    if ($condition instanceof ContextAwarePluginInterface) {
      try {
        $contextMapping = $condition
          ->getContextMapping();
        if ($contextMapping) {
          $contexts = $this->contextRepository
            ->getRuntimeContexts(array_values($contextMapping));
          $this->contextHandler
            ->applyContextMapping($condition, $contexts);
        }
      } catch (ContextException $e) {

        // @todo: Think the best way to handle this.
      }
    }
    $conditions[$conditionId] = $condition;
  }
  return $conditions;
}