|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\entity_browser; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; |
|
6
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
7
|
|
|
use Drupal\Core\StringTranslation\TranslationManager; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Generates routes for entity browsers. |
|
12
|
|
|
*/ |
|
13
|
|
|
class Permissions implements ContainerInjectionInterface { |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The entity browser storage. |
|
17
|
|
|
* |
|
18
|
|
|
* @var \Drupal\Core\Entity\EntityStorageInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $browserStorage; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Translation manager service. |
|
24
|
|
|
* |
|
25
|
|
|
* @var \Drupal\Core\StringTranslation\TranslationManager |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $translationManager; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Constructs Permissions object. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
|
33
|
|
|
* Entity manager service. |
|
34
|
|
|
* @param \Drupal\Core\StringTranslation\TranslationManager $translation |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationManager $translation) { |
|
37
|
|
|
$this->browserStorage = $entity_type_manager->getStorage('entity_browser'); |
|
38
|
|
|
$this->translationManager = $translation; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
public static function create(ContainerInterface $container) { |
|
45
|
|
|
return new static( |
|
46
|
|
|
$container->get('entity_type.manager'), |
|
47
|
|
|
$container->get('string_translation') |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Dynamically set permissions for entity browsers with routes. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function permissions() { |
|
55
|
|
|
$permissions = []; |
|
56
|
|
|
/** @var \Drupal\entity_browser\EntityBrowserInterface[] $browsers */ |
|
57
|
|
|
$browsers = $this->browserStorage->loadMultiple(); |
|
58
|
|
|
|
|
59
|
|
|
foreach ($browsers as $browser) { |
|
60
|
|
|
if ($browser->route()) { |
|
61
|
|
|
$permissions['access ' . $browser->id() . ' entity browser pages'] = [ |
|
62
|
|
|
'title' => $this->translationManager->translate('Access @name pages', ['@name' => $browser->label()]), |
|
63
|
|
|
'description' => $this->translationManager->translate('Access pages that %browser uses to operate.', ['%browser' => $browser->label()]), |
|
64
|
|
|
]; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $permissions; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|