You are here

class AutoEntityLabelPermissionController in Automatic Entity Label 8.3

Same name and namespace in other branches
  1. 8 src/AutoEntityLabelPermissionController.php \Drupal\auto_entitylabel\AutoEntityLabelPermissionController
  2. 8.2 src/AutoEntityLabelPermissionController.php \Drupal\auto_entitylabel\AutoEntityLabelPermissionController

Provides dynamic permissions of the auto_entitylabel module.

Hierarchy

Expanded class hierarchy of AutoEntityLabelPermissionController

1 file declares its use of AutoEntityLabelPermissionController
AutoEntityLabelPermissionControllerTest.php in tests/src/Kernel/AutoEntityLabelPermissionControllerTest.php

File

src/AutoEntityLabelPermissionController.php, line 13

Namespace

Drupal\auto_entitylabel
View source
class AutoEntityLabelPermissionController implements ContainerInjectionInterface {
  use StringTranslationTrait;

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

  /**
   * Constructs a new AutoEntityLabelPermissionController instance.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   */
  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'));
  }

  /**
   * Returns an array of auto_entitylabel permissions.
   *
   * @return array
   *   Array with permissions.
   */
  public function autoEntityLabelPermissions() {
    $permissions = [];
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {

      // Create a permission for each entity type to manage the entity
      // labels.
      if ($entity_type
        ->hasLinkTemplate('auto-label') && $entity_type
        ->hasKey('label')) {
        $permissions['administer ' . $entity_type_id . ' labels'] = [
          'title' => $this
            ->t('%entity_label: Administer automatic entity labels', [
            '%entity_label' => $entity_type
              ->getLabel(),
          ]),
          'restrict access' => TRUE,
        ];
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AutoEntityLabelPermissionController::$entityTypeManager protected property The entity type manager.
AutoEntityLabelPermissionController::autoEntityLabelPermissions public function Returns an array of auto_entitylabel permissions.
AutoEntityLabelPermissionController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
AutoEntityLabelPermissionController::__construct public function Constructs a new AutoEntityLabelPermissionController instance.
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.