You are here

class TaxonomyPermissions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/taxonomy/src/TaxonomyPermissions.php \Drupal\taxonomy\TaxonomyPermissions

Provides dynamic permissions of the taxonomy module.

Hierarchy

Expanded class hierarchy of TaxonomyPermissions

See also

taxonomy.permissions.yml

File

core/modules/taxonomy/src/TaxonomyPermissions.php, line 20
Contains \Drupal\taxonomy\TaxonomyPermissions.

Namespace

Drupal\taxonomy
View source
class TaxonomyPermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * Constructs a TaxonomyPermissions instance.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityManagerInterface $entity_manager) {
    $this->entityManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity.manager'));
  }

  /**
   * Get taxonomy permissions.
   *
   * @return array
   *   Permissions array.
   */
  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(),
          ]),
        ],
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TaxonomyPermissions::$entityManager protected property The entity manager.
TaxonomyPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
TaxonomyPermissions::permissions public function Get taxonomy permissions.
TaxonomyPermissions::__construct public function Constructs a TaxonomyPermissions instance.