class DashboardsPermissions in Dashboards with Layout Builder 8
Same name and namespace in other branches
- 2.0.x src/DashboardsPermissions.php \Drupal\dashboards\DashboardsPermissions
Dashboard permissions.
Hierarchy
- class \Drupal\dashboards\DashboardsPermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of DashboardsPermissions
File
- src/
DashboardsPermissions.php, line 13
Namespace
Drupal\dashboardsView source
class DashboardsPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
/**
* Constructs a DashboardsPermissions instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
/**
* Gets dashboard permission.
*
* @return array
* An array of permissions.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function permissions() : array {
$permissions = [];
foreach ($this->entityManager
->getStorage('dashboard')
->loadMultiple() as $dashboard) {
$permissions += [
'can view ' . $dashboard
->id() . ' dashboard' => [
'title' => $this
->t('Can view %dashboard dashboard.', [
'%dashboard' => $dashboard
->label(),
]),
],
];
$permissions += [
'can override ' . $dashboard
->id() . ' dashboard' => [
'title' => $this
->t('Can override %dashboard dashboard', [
'%dashboard' => $dashboard
->label(),
]),
],
];
}
return $permissions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DashboardsPermissions:: |
protected | property | The entity manager. | |
DashboardsPermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
DashboardsPermissions:: |
public | function | Gets dashboard permission. | |
DashboardsPermissions:: |
public | function | Constructs a DashboardsPermissions instance. | |
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. |