You are here

class CommerceAutoSkuPermissionController in Commerce AutoSKU 8.2

Provides dynamic permissions of the commerce_autosku module.

Hierarchy

Expanded class hierarchy of CommerceAutoSkuPermissionController

File

src/CommerceAutoSkuPermissionController.php, line 19
Contains \Drupal\commerce_autosku\AutoEntityLabelPermissionController.

Namespace

Drupal\commerce_autosku
View source
class CommerceAutoSkuPermissionController implements ContainerInjectionInterface {
  use StringTranslationTrait;

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

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

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

  /**
   * Returns an array of commerce_autosku permissions
   *
   * @return array
   */
  public function autoSkuPermissions() {
    $permissions = [];
    foreach ($this->entityManager
      ->getDefinitions() as $entity_type_id => $entity_type) {

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

}

Members

Namesort descending Modifiers Type Description Overrides
CommerceAutoSkuPermissionController::$entityManager protected property The entity manager.
CommerceAutoSkuPermissionController::autoSkuPermissions public function Returns an array of commerce_autosku permissions
CommerceAutoSkuPermissionController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
CommerceAutoSkuPermissionController::__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.