LanguageCookieConditionManager.php in Language Cookie 8
File
src/LanguageCookieConditionManager.php
View source
<?php
namespace Drupal\language_cookie;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Executable\ExecutableInterface;
use Drupal\Core\Executable\ExecutableManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\language_cookie\Annotation\LanguageCookieCondition;
class LanguageCookieConditionManager extends DefaultPluginManager implements ExecutableManagerInterface {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/LanguageCookieCondition', $namespaces, $module_handler, LanguageCookieConditionInterface::class, LanguageCookieCondition::class);
$this
->setCacheBackend($cache_backend, 'language_cookie_condition_plugins');
$this
->alterInfo('language_cookie_condition_info');
}
public function getDefinitions() {
$definitions = parent::getDefinitions();
uasort($definitions, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
return $definitions;
}
public function createInstance($plugin_id, array $configuration = []) {
$plugin = $this
->getFactory()
->createInstance($plugin_id, $configuration);
if (!empty($configuration['context'])) {
foreach ($configuration['context'] as $name => $context) {
$plugin
->setContextValue($name, $context);
}
}
return $plugin
->setExecutableManager($this);
}
public function execute(ExecutableInterface $condition) {
return $condition
->evaluate();
}
}