3 namespace Drupal\taxonomy;
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
8 use Drupal\taxonomy\Entity\Vocabulary;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Provides dynamic permissions of the taxonomy module.
14 * @see taxonomy.permissions.yml
16 class TaxonomyPermissions implements ContainerInjectionInterface {
18 use StringTranslationTrait;
23 * @var \Drupal\Core\Entity\EntityManagerInterface
25 protected $entityManager;
28 * Constructs a TaxonomyPermissions instance.
30 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
33 public function __construct(EntityManagerInterface $entity_manager) {
34 $this->entityManager = $entity_manager;
40 public static function create(ContainerInterface $container) {
41 return new static($container->get('entity.manager'));
45 * Get taxonomy permissions.
50 public function permissions() {
52 foreach (Vocabulary::loadMultiple() as $vocabulary) {
53 $permissions += $this->buildPermissions($vocabulary);
59 * Builds a standard list of taxonomy term permissions for a given vocabulary.
61 * @param \Drupal\taxonomy\VocabularyInterface $vocabulary
65 * An array of permission names and descriptions.
67 protected function buildPermissions(VocabularyInterface $vocabulary) {
68 $id = $vocabulary->id();
69 $args = ['%vocabulary' => $vocabulary->label()];
72 "create terms in $id" => ['title' => $this->t('%vocabulary: Create terms', $args)],
73 "delete terms in $id" => ['title' => $this->t('%vocabulary: Delete terms', $args)],
74 "edit terms in $id" => ['title' => $this->t('%vocabulary: Edit terms', $args)],