class Permissions in Avatar Kit 8
Define a permission generator.
Hierarchy
- class \Drupal\avatars\Permissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of Permissions
File
- src/
Permissions.php, line 12
Namespace
Drupal\avatarsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Permissions:: |
protected | property | The avatar generator plugin manager. | |
Permissions:: |
public | function | Define permissions for picture providers. | |
Permissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
Permissions:: |
public | function | Constructs the permission generator. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |