You are here

class InvitePermissions in Invite 8

Provides dynamic permissions of the invite module.

Hierarchy

Expanded class hierarchy of InvitePermissions

File

src/InvitePermissions.php, line 13

Namespace

Drupal\invite
View source
class InvitePermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

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

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

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

  /**
   * Returns an array of invite permissions.
   *
   * @return array
   *   Returns the array with permissions.
   */
  public function permissions() {
    $permissions = [];

    // Generate permissions for each invite type.
    $invite_types = $this->entityTypeManager
      ->getStorage('invite_type')
      ->loadMultiple();
    foreach ($invite_types as $invite_type) {
      $permissions['invite_type_' . $invite_type
        ->getType()] = [
        'title' => $this
          ->t('Create @label invites', [
          '@label' => $invite_type
            ->label(),
        ]),
        'description' => [
          '#prefix' => '<em>',
          '#markup' => $this
            ->t('Warning: This permission could have security implications.'),
          '#suffix' => '</em>',
        ],
      ];
    }
    return $permissions;
  }

}

Members

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