FilterAccess.php in Workbench Access 8
File
tests/modules/workbench_access_filter_test/src/Plugin/AccessControlHierarchy/FilterAccess.php
View source
<?php
namespace Drupal\workbench_access_filter_test\Plugin\AccessControlHierarchy;
use Drupal\Core\Entity\EntityInterface;
use Drupal\filter\FilterPluginManager;
use Drupal\workbench_access\AccessControlHierarchyBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FilterAccess extends AccessControlHierarchyBase {
protected $filterPluginManager;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
return $instance
->setFilterPluginManager($container
->get('plugin.manager.filter'));
}
public function getTree() {
$tree = [];
$tree['filter']['filters'] = [
'label' => 'Filters',
'depth' => 0,
'parents' => [],
'weight' => 0,
'description' => 'Filters',
];
$weight = 1;
foreach ($this->filterPluginManager
->getDefinitions() as $id => $definition) {
$tree['filter'][$id] = [
'label' => isset($definition['label']) ? $definition['label'] : $id,
'depth' => 1,
'parents' => [
'filters',
],
'weight' => $weight++,
'description' => $definition['description'],
];
}
return $tree;
}
public function getEntityValues(EntityInterface $entity) {
return array_keys(array_filter(iterator_to_array($entity
->filters()), function ($filter) {
return $filter->status;
}));
}
public function applies($entity_type_id, $bundle) {
return $entity_type_id === 'filter_format';
}
public function setFilterPluginManager(FilterPluginManager $manager) {
$this->filterPluginManager = $manager;
return $this;
}
}
Classes
Name |
Description |
FilterAccess |
Defines a test hierarchy for the sake of config entity access. |