Mercurial > hg > isophonics-drupal-site
comparison core/modules/taxonomy/src/TaxonomyPermissions.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\taxonomy; | |
4 | |
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface; | |
6 use Drupal\Core\Entity\EntityManagerInterface; | |
7 use Drupal\Core\StringTranslation\StringTranslationTrait; | |
8 use Symfony\Component\DependencyInjection\ContainerInterface; | |
9 | |
10 /** | |
11 * Provides dynamic permissions of the taxonomy module. | |
12 * | |
13 * @see taxonomy.permissions.yml | |
14 */ | |
15 class TaxonomyPermissions implements ContainerInjectionInterface { | |
16 | |
17 use StringTranslationTrait; | |
18 | |
19 /** | |
20 * The entity manager. | |
21 * | |
22 * @var \Drupal\Core\Entity\EntityManagerInterface | |
23 */ | |
24 protected $entityManager; | |
25 | |
26 /** | |
27 * Constructs a TaxonomyPermissions instance. | |
28 * | |
29 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager | |
30 * The entity manager. | |
31 */ | |
32 public function __construct(EntityManagerInterface $entity_manager) { | |
33 $this->entityManager = $entity_manager; | |
34 } | |
35 | |
36 /** | |
37 * {@inheritdoc} | |
38 */ | |
39 public static function create(ContainerInterface $container) { | |
40 return new static($container->get('entity.manager')); | |
41 } | |
42 | |
43 /** | |
44 * Get taxonomy permissions. | |
45 * | |
46 * @return array | |
47 * Permissions array. | |
48 */ | |
49 public function permissions() { | |
50 $permissions = []; | |
51 foreach ($this->entityManager->getStorage('taxonomy_vocabulary')->loadMultiple() as $vocabulary) { | |
52 $permissions += [ | |
53 'edit terms in ' . $vocabulary->id() => [ | |
54 'title' => $this->t('Edit terms in %vocabulary', ['%vocabulary' => $vocabulary->label()]), | |
55 ], | |
56 ]; | |
57 $permissions += [ | |
58 'delete terms in ' . $vocabulary->id() => [ | |
59 'title' => $this->t('Delete terms from %vocabulary', ['%vocabulary' => $vocabulary->label()]), | |
60 ], | |
61 ]; | |
62 } | |
63 return $permissions; | |
64 } | |
65 | |
66 } |