Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\rest;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
Chris@0
|
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
|
Chris@0
|
7 use Drupal\rest\Plugin\Type\ResourcePluginManager;
|
Chris@0
|
8 use Symfony\Component\DependencyInjection\ContainerInterface;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Provides rest module permissions.
|
Chris@0
|
12 */
|
Chris@0
|
13 class RestPermissions implements ContainerInjectionInterface {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * The rest resource plugin manager.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var \Drupal\rest\Plugin\Type\ResourcePluginManager
|
Chris@0
|
19 */
|
Chris@0
|
20 protected $restPluginManager;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * The REST resource config storage.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @var \Drupal\Core\Entity\EntityManagerInterface
|
Chris@0
|
26 */
|
Chris@0
|
27 protected $resourceConfigStorage;
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * Constructs a new RestPermissions instance.
|
Chris@0
|
31 *
|
Chris@0
|
32 * @param \Drupal\rest\Plugin\Type\ResourcePluginManager $rest_plugin_manager
|
Chris@0
|
33 * The rest resource plugin manager.
|
Chris@0
|
34 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
Chris@0
|
35 * The entity type manager.
|
Chris@0
|
36 */
|
Chris@0
|
37 public function __construct(ResourcePluginManager $rest_plugin_manager, EntityTypeManagerInterface $entity_type_manager) {
|
Chris@0
|
38 $this->restPluginManager = $rest_plugin_manager;
|
Chris@0
|
39 $this->resourceConfigStorage = $entity_type_manager->getStorage('rest_resource_config');
|
Chris@0
|
40 }
|
Chris@0
|
41
|
Chris@0
|
42 /**
|
Chris@0
|
43 * {@inheritdoc}
|
Chris@0
|
44 */
|
Chris@0
|
45 public static function create(ContainerInterface $container) {
|
Chris@0
|
46 return new static($container->get('plugin.manager.rest'), $container->get('entity_type.manager'));
|
Chris@0
|
47 }
|
Chris@0
|
48
|
Chris@0
|
49 /**
|
Chris@0
|
50 * Returns an array of REST permissions.
|
Chris@0
|
51 *
|
Chris@0
|
52 * @return array
|
Chris@0
|
53 */
|
Chris@0
|
54 public function permissions() {
|
Chris@0
|
55 $permissions = [];
|
Chris@0
|
56 /** @var \Drupal\rest\RestResourceConfigInterface[] $resource_configs */
|
Chris@0
|
57 $resource_configs = $this->resourceConfigStorage->loadMultiple();
|
Chris@0
|
58 foreach ($resource_configs as $resource_config) {
|
Chris@0
|
59 $plugin = $resource_config->getResourcePlugin();
|
Chris@0
|
60 $permissions = array_merge($permissions, $plugin->permissions());
|
Chris@0
|
61 }
|
Chris@0
|
62 return $permissions;
|
Chris@0
|
63 }
|
Chris@0
|
64
|
Chris@0
|
65 }
|