You are here

class Permissions in Entity Browser 8.2

Same name and namespace in other branches
  1. 8 src/Permissions.php \Drupal\entity_browser\Permissions

Generates routes for entity browsers.

Hierarchy

Expanded class hierarchy of Permissions

File

src/Permissions.php, line 13

Namespace

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

  /**
   * The entity browser storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $browserStorage;

  /**
   * Constructs Permissions object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity manager service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->browserStorage = $entity_type_manager
      ->getStorage('entity_browser');
  }

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

  /**
   * Dynamically set permissions for entity browsers with routes.
   */
  public function permissions() {
    $permissions = [];

    /** @var \Drupal\entity_browser\EntityBrowserInterface[] $browsers */
    $browsers = $this->browserStorage
      ->loadMultiple();
    foreach ($browsers as $browser) {
      if ($browser
        ->route()) {
        $permissions['access ' . $browser
          ->id() . ' entity browser pages'] = [
          'title' => $this
            ->t('Access @name pages', [
            '@name' => $browser
              ->label(),
          ]),
          'description' => $this
            ->t('Access pages that %browser uses to operate.', [
            '%browser' => $browser
              ->label(),
          ]),
        ];
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Permissions::$browserStorage protected property The entity browser storage.
Permissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
Permissions::permissions public function Dynamically set permissions for entity browsers with routes.
Permissions::__construct public function Constructs Permissions object.
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.