You are here

class DashboardsPermissions in Dashboards with Layout Builder 8

Same name and namespace in other branches
  1. 2.0.x src/DashboardsPermissions.php \Drupal\dashboards\DashboardsPermissions

Dashboard permissions.

Hierarchy

Expanded class hierarchy of DashboardsPermissions

File

src/DashboardsPermissions.php, line 13

Namespace

Drupal\dashboards
View 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

Namesort descending Modifiers Type Description Overrides
DashboardsPermissions::$entityManager protected property The entity manager.
DashboardsPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
DashboardsPermissions::permissions public function Gets dashboard permission.
DashboardsPermissions::__construct public function Constructs a DashboardsPermissions 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.