You are here

class Permissions in Avatar Kit 8

Define a permission generator.

Hierarchy

Expanded class hierarchy of Permissions

File

src/Permissions.php, line 12

Namespace

Drupal\avatars
View source
class Permissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The avatar generator plugin manager.
   *
   * @var \Drupal\avatars\AvatarGeneratorPluginManagerInterface
   */
  protected $avatarGenerator;

  /**
   * Constructs the permission generator.
   *
   * @param \Drupal\avatars\AvatarGeneratorPluginManagerInterface $avatar_generator
   *   The avatar generator plugin manager.
   */
  public function __construct(AvatarGeneratorPluginManagerInterface $avatar_generator) {
    $this->avatarGenerator = $avatar_generator;
  }

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

  /**
   * Define permissions for picture providers.
   *
   * @return array
   *   An array of permissions.
   */
  public function avatarGenerators() {
    $permissions = [];

    /** @var \Drupal\avatars\AvatarGeneratorStorageInterface $avatars_generator_storage */
    $avatars_generator_storage = \Drupal::entityTypeManager()
      ->getStorage('avatar_generator');
    foreach ($avatars_generator_storage
      ->loadMultiple() as $instance) {
      if ($instance
        ->getPlugin()
        ->getPluginId() == 'user_preference') {
        continue;
      }
      $t_args = [
        '%label' => $instance
          ->label(),
      ];
      $permissions["avatars avatar_generator user " . $instance
        ->id()] = [
        'title' => $this
          ->t('Use %label', $t_args),
        'description' => $this
          ->t('User can select %label avatar generator.', $t_args),
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Permissions::$avatarGenerator protected property The avatar generator plugin manager.
Permissions::avatarGenerators public function Define permissions for picture providers.
Permissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
Permissions::__construct public function Constructs the permission generator.
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.