class TawkToConditionPluginsHandler in Tawk.to - Live chat application (Drupal 8) 8
Same name and namespace in other branches
- 8.2 src/Service/TawkToConditionPluginsHandler.php \Drupal\tawk_to\Service\TawkToConditionPluginsHandler
Defines the condition plugins handler.
Hierarchy
- class \Drupal\tawk_to\Service\TawkToConditionPluginsHandler uses ConditionAccessResolverTrait
Expanded class hierarchy of TawkToConditionPluginsHandler
1 file declares its use of TawkToConditionPluginsHandler
- TawkToCacheManager.php in src/
Cache/ TawkToCacheManager.php
1 string reference to 'TawkToConditionPluginsHandler'
1 service uses TawkToConditionPluginsHandler
File
- src/
Service/ TawkToConditionPluginsHandler.php, line 16
Namespace
Drupal\tawk_to\ServiceView source
class TawkToConditionPluginsHandler {
use ConditionAccessResolverTrait;
/**
* The plugin context handler.
*
* @var \Drupal\Core\Plugin\Context\ContextHandlerInterface
*/
protected $contextHandler;
/**
* The context manager service.
*
* @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface
*/
protected $contextRepository;
/**
* The condition plugin manager.
*
* @var \Drupal\Core\Condition\ConditionManager
*/
protected $manager;
/**
* The condition plugin defination.
*
* @var array
*/
protected $tawkToVisibility;
/**
* Constructs the tawk.to access control handler instance.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The factory for configuration objects.
* @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $contextHandler
* The ContextHandler for applying contexts to conditions properly.
* @param \Drupal\Core\Plugin\Context\ContextRepositoryInterface $contextRepository
* The lazy context repository service.
* @param \Drupal\Core\Executable\ExecutableManagerInterface $manager
* The ConditionManager for building the visibility UI.
*/
public function __construct(ConfigFactoryInterface $configFactory, ContextHandlerInterface $contextHandler, ContextRepositoryInterface $contextRepository, ExecutableManagerInterface $manager) {
$this->tawkToVisibility = $configFactory
->get('tawk_to.settings')
->get('visibility');
$this->contextHandler = $contextHandler;
$this->contextRepository = $contextRepository;
$this->manager = $manager;
}
/**
* {@inheritdoc}
*/
public function checkAccess() {
$conditions = [];
if (!empty($this->tawkToVisibility)) {
$conditions = $this
->getConditions();
return $this
->resolveConditions($conditions, 'and');
}
return TRUE;
}
/**
* Gets condition plugins based on the module configuration.
*
* @return \Drupal\Core\Condition\ConditionInterface[]
* A set of conditions.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConditionAccessResolverTrait:: |
protected | function | Resolves the given conditions based on the condition logic ('and'/'or'). | |
TawkToConditionPluginsHandler:: |
protected | property | The plugin context handler. | |
TawkToConditionPluginsHandler:: |
protected | property | The context manager service. | |
TawkToConditionPluginsHandler:: |
protected | property | The condition plugin manager. | |
TawkToConditionPluginsHandler:: |
protected | property | The condition plugin defination. | |
TawkToConditionPluginsHandler:: |
public | function | ||
TawkToConditionPluginsHandler:: |
public | function | Gets condition plugins based on the module configuration. | |
TawkToConditionPluginsHandler:: |
public | function | Constructs the tawk.to access control handler instance. |