5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Drupal\rest\Plugin\Type\ResourcePluginManager;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Provides rest module permissions.
13 class RestPermissions implements ContainerInjectionInterface {
16 * The rest resource plugin manager.
18 * @var \Drupal\rest\Plugin\Type\ResourcePluginManager
20 protected $restPluginManager;
23 * The REST resource config storage.
25 * @var \Drupal\Core\Entity\EntityManagerInterface
27 protected $resourceConfigStorage;
30 * Constructs a new RestPermissions instance.
32 * @param \Drupal\rest\Plugin\Type\ResourcePluginManager $rest_plugin_manager
33 * The rest resource plugin manager.
34 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
35 * The entity type manager.
37 public function __construct(ResourcePluginManager $rest_plugin_manager, EntityTypeManagerInterface $entity_type_manager) {
38 $this->restPluginManager = $rest_plugin_manager;
39 $this->resourceConfigStorage = $entity_type_manager->getStorage('rest_resource_config');
45 public static function create(ContainerInterface $container) {
46 return new static($container->get('plugin.manager.rest'), $container->get('entity_type.manager'));
50 * Returns an array of REST permissions.
54 public function permissions() {
56 /** @var \Drupal\rest\RestResourceConfigInterface[] $resource_configs */
57 $resource_configs = $this->resourceConfigStorage->loadMultiple();
58 foreach ($resource_configs as $resource_config) {
59 $plugin = $resource_config->getResourcePlugin();
60 $permissions = array_merge($permissions, $plugin->permissions());