TaxonomyPermissions.php in Drupal 8
File
core/modules/taxonomy/src/TaxonomyPermissions.php
View source
<?php
namespace Drupal\taxonomy;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\taxonomy\Entity\Vocabulary;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TaxonomyPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
use DeprecatedServicePropertyTrait;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
public function permissions() {
$permissions = [];
foreach (Vocabulary::loadMultiple() as $vocabulary) {
$permissions += $this
->buildPermissions($vocabulary);
}
return $permissions;
}
protected function buildPermissions(VocabularyInterface $vocabulary) {
$id = $vocabulary
->id();
$args = [
'%vocabulary' => $vocabulary
->label(),
];
return [
"create terms in {$id}" => [
'title' => $this
->t('%vocabulary: Create terms', $args),
],
"delete terms in {$id}" => [
'title' => $this
->t('%vocabulary: Delete terms', $args),
],
"edit terms in {$id}" => [
'title' => $this
->t('%vocabulary: Edit terms', $args),
],
];
}
}