comparison core/modules/taxonomy/src/TaxonomyPermissions.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
3 namespace Drupal\taxonomy; 3 namespace Drupal\taxonomy;
4 4
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface; 5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Drupal\Core\Entity\EntityManagerInterface; 6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\StringTranslation\StringTranslationTrait; 7 use Drupal\Core\StringTranslation\StringTranslationTrait;
8 use Drupal\taxonomy\Entity\Vocabulary;
8 use Symfony\Component\DependencyInjection\ContainerInterface; 9 use Symfony\Component\DependencyInjection\ContainerInterface;
9 10
10 /** 11 /**
11 * Provides dynamic permissions of the taxonomy module. 12 * Provides dynamic permissions of the taxonomy module.
12 * 13 *
46 * @return array 47 * @return array
47 * Permissions array. 48 * Permissions array.
48 */ 49 */
49 public function permissions() { 50 public function permissions() {
50 $permissions = []; 51 $permissions = [];
51 foreach ($this->entityManager->getStorage('taxonomy_vocabulary')->loadMultiple() as $vocabulary) { 52 foreach (Vocabulary::loadMultiple() as $vocabulary) {
52 $permissions += [ 53 $permissions += $this->buildPermissions($vocabulary);
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 } 54 }
63 return $permissions; 55 return $permissions;
64 } 56 }
65 57
58 /**
59 * Builds a standard list of taxonomy term permissions for a given vocabulary.
60 *
61 * @param \Drupal\taxonomy\VocabularyInterface $vocabulary
62 * The vocabulary.
63 *
64 * @return array
65 * An array of permission names and descriptions.
66 */
67 protected function buildPermissions(VocabularyInterface $vocabulary) {
68 $id = $vocabulary->id();
69 $args = ['%vocabulary' => $vocabulary->label()];
70
71 return [
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)],
75 ];
76 }
77
66 } 78 }