ConditionManager.php in Drupal 8
File
core/lib/Drupal/Core/Condition/ConditionManager.php
View source
<?php
namespace Drupal\Core\Condition;
use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Executable\ExecutableException;
use Drupal\Core\Executable\ExecutableManagerInterface;
use Drupal\Core\Executable\ExecutableInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\FilteredPluginManagerInterface;
use Drupal\Core\Plugin\FilteredPluginManagerTrait;
class ConditionManager extends DefaultPluginManager implements ExecutableManagerInterface, CategorizingPluginManagerInterface, FilteredPluginManagerInterface {
use CategorizingPluginManagerTrait;
use FilteredPluginManagerTrait;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
$this
->alterInfo('condition_info');
$this
->setCacheBackend($cache_backend, 'condition_plugins');
parent::__construct('Plugin/Condition', $namespaces, $module_handler, 'Drupal\\Core\\Condition\\ConditionInterface', 'Drupal\\Core\\Condition\\Annotation\\Condition');
}
protected function getType() {
return 'condition';
}
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) {
if ($condition instanceof ConditionInterface) {
$result = $condition
->evaluate();
return $condition
->isNegated() ? !$result : $result;
}
throw new ExecutableException("This manager object can only execute condition plugins");
}
}