View source
<?php
namespace Drupal\entity_browser;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Permissions implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $browserStorage;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->browserStorage = $entity_type_manager
->getStorage('entity_browser');
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
public function permissions() {
$permissions = [];
$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;
}
}