You are here

class ConfigPagesPermissions in Config Pages 8.2

Same name and namespace in other branches
  1. 8.3 src/ConfigPagesPermissions.php \Drupal\config_pages\ConfigPagesPermissions

Provides rest module permissions.

Hierarchy

Expanded class hierarchy of ConfigPagesPermissions

File

src/ConfigPagesPermissions.php, line 13

Namespace

Drupal\config_pages
View source
class ConfigPagesPermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The config_pages config storage.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $storage;

  /**
   * Constructs a new ConfigPagesPermissions instance.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->storage = $entity_type_manager
      ->getStorage('config_pages_type');
  }

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

  /**
   * Returns an array of Config pages permissions.
   *
   * @return array
   *   Permissions.
   */
  public function permissions() {
    $permissions = [];
    $config_pages = $this->storage
      ->loadMultiple();
    foreach ($config_pages as $config_page) {
      $permissions['view ' . $config_page
        ->id() . ' config page entity'] = [
        'title' => $this
          ->t('View the @label config page entity', [
          '@label' => $config_page
            ->label(),
        ]),
      ];
      $permissions['edit ' . $config_page
        ->id() . ' config page entity'] = [
        'title' => $this
          ->t('Edit the @label config page entity', [
          '@label' => $config_page
            ->label(),
        ]),
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigPagesPermissions::$storage protected property The config_pages config storage.
ConfigPagesPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
ConfigPagesPermissions::permissions public function Returns an array of Config pages permissions.
ConfigPagesPermissions::__construct public function Constructs a new ConfigPagesPermissions 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.