diff 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
line wrap: on
line diff
--- a/core/modules/taxonomy/src/TaxonomyPermissions.php	Mon Apr 23 09:33:26 2018 +0100
+++ b/core/modules/taxonomy/src/TaxonomyPermissions.php	Mon Apr 23 09:46:53 2018 +0100
@@ -5,6 +5,7 @@
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
 use Drupal\Core\Entity\EntityManagerInterface;
 use Drupal\Core\StringTranslation\StringTranslationTrait;
+use Drupal\taxonomy\Entity\Vocabulary;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -48,19 +49,30 @@
    */
   public function permissions() {
     $permissions = [];
-    foreach ($this->entityManager->getStorage('taxonomy_vocabulary')->loadMultiple() as $vocabulary) {
-      $permissions += [
-        'edit terms in ' . $vocabulary->id() => [
-          'title' => $this->t('Edit terms in %vocabulary', ['%vocabulary' => $vocabulary->label()]),
-        ],
-      ];
-      $permissions += [
-        'delete terms in ' . $vocabulary->id() => [
-          'title' => $this->t('Delete terms from %vocabulary', ['%vocabulary' => $vocabulary->label()]),
-        ],
-      ];
+    foreach (Vocabulary::loadMultiple() as $vocabulary) {
+      $permissions += $this->buildPermissions($vocabulary);
     }
     return $permissions;
   }
 
+  /**
+   * Builds a standard list of taxonomy term permissions for a given vocabulary.
+   *
+   * @param \Drupal\taxonomy\VocabularyInterface $vocabulary
+   *   The vocabulary.
+   *
+   * @return array
+   *   An array of permission names and descriptions.
+   */
+  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)],
+    ];
+  }
+
 }