You are here

class TcaPermissionGenerator in Token Content Access 2.0.x

Same name and namespace in other branches
  1. 8 src/TcaPermissionGenerator.php \Drupal\tca\TcaPermissionGenerator

Class TcaPermissionGenerator.

@package Drupal\tca

Hierarchy

Expanded class hierarchy of TcaPermissionGenerator

File

src/TcaPermissionGenerator.php, line 17

Namespace

Drupal\tca
View source
class TcaPermissionGenerator implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * Drupal\Core\Entity\EntityTypeManager definition.
   *
   * @var Drupal\Core\Entity\EntityTypeManager
   */
  private $entityTypeManager = NULL;

  /**
   * Drupal\tca\Plugin\TcaPluginManager definition.
   *
   * @var Drupal\tca\Plugin\TcaPluginManager
   */
  private $tcaPluginManager = NULL;

  /**
   * Constructor.
   */
  public function __construct(EntityTypeManagerInterface $etm, TcaPluginManager $tca_plugin_manager, TranslationInterface $translation) {
    $this->entityTypeManager = $etm;
    $this->tcaPluginManager = $tca_plugin_manager;
    $this->stringTranslation = $translation;
  }

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

  /**
   * Return an array of per-entity tca permissions.
   *
   * @return array
   *   An array of permissions
   */
  public function permissions() {
    $permissions = [];
    foreach ($this->tcaPluginManager
      ->getDefinitions() as $def) {
      $entity_type = $this->entityTypeManager
        ->getStorage($def['entityType'])
        ->getEntityType();
      $permissions += [
        'tca administer ' . $def['entityType'] => [
          'title' => $this
            ->t('Administer Token Content Access settings for %entity_type', [
            '%entity_type' => $entity_type
              ->getLabel(),
          ]),
        ],
        'tca bypass ' . $def['entityType'] => [
          'title' => $this
            ->t('Bypass Token Content Access action for %entity_type', [
            '%entity_type' => $entity_type
              ->getLabel(),
          ]),
        ],
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.
TcaPermissionGenerator::$entityTypeManager private property Drupal\Core\Entity\EntityTypeManager definition.
TcaPermissionGenerator::$tcaPluginManager private property Drupal\tca\Plugin\TcaPluginManager definition.
TcaPermissionGenerator::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
TcaPermissionGenerator::permissions public function Return an array of per-entity tca permissions.
TcaPermissionGenerator::__construct public function Constructor.