You are here

class TaxonomyPermissions in Drupal 8

Same name and namespace in other branches
  1. 9 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 17

Namespace

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

  /**
   * {@inheritdoc}
   */
  protected $deprecatedProperties = [
    'entityManager' => 'entity.manager',
  ];

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

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

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

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

}

Members

Namesort descending Modifiers Type Description Overrides
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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::$deprecatedProperties protected property
TaxonomyPermissions::$entityTypeManager protected property The entity type manager.
TaxonomyPermissions::buildPermissions protected function Builds a standard list of taxonomy term permissions for a given vocabulary.
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.