summaryrefslogtreecommitdiffstats
path: root/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
diff options
context:
space:
mode:
authorAlex Pott2016-08-01 15:09:47 +0100
committerAlex Pott2016-08-01 15:09:47 +0100
commit85d755a992d89ac101580a9d3fa692b2b3ed7112 (patch)
treeaf5f5fc064e18e0844fe4d45c1070897a03f41c6 /core/modules/rest/src/Plugin/rest/resource/EntityResource.php
parent9bc59ded3e700fe2e46907df41d06998a9ec3a47 (diff)
Issue #2664780 by Wim Leers, tedbow, dawehner, klausi: Remove REST's resource- and verb-specific permissions for EntityResource, but provide BC and document why it's necessary for other resources
Diffstat (limited to 'core/modules/rest/src/Plugin/rest/resource/EntityResource.php')
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php31
1 files changed, 29 insertions, 2 deletions
diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
index 8b96940..5cf42dd 100644
--- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
@@ -6,6 +6,7 @@ use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\rest\Plugin\ResourceBase;
@@ -43,6 +44,13 @@ class EntityResource extends ResourceBase implements DependentPluginInterface {
protected $entityType;
/**
+ * The config factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
* Constructs a Drupal\rest\Plugin\rest\resource\EntityResource object.
*
* @param array $configuration
@@ -57,10 +65,13 @@ class EntityResource extends ResourceBase implements DependentPluginInterface {
* The available serialization formats.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
+ * @param \Drupal\Core\Config\ConfigFactoryInterface
+ * The config factory.
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, $serializer_formats, LoggerInterface $logger) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, $serializer_formats, LoggerInterface $logger, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger);
$this->entityType = $entity_type_manager->getDefinition($plugin_definition['entity_type']);
+ $this->configFactory = $config_factory;
}
/**
@@ -73,7 +84,8 @@ class EntityResource extends ResourceBase implements DependentPluginInterface {
$plugin_definition,
$container->get('entity_type.manager'),
$container->getParameter('serializer.formats'),
- $container->get('logger.factory')->get('rest')
+ $container->get('logger.factory')->get('rest'),
+ $container->get('config.factory')
);
}
@@ -300,6 +312,21 @@ class EntityResource extends ResourceBase implements DependentPluginInterface {
/**
* {@inheritdoc}
*/
+ public function permissions() {
+ // @see https://www.drupal.org/node/2664780
+ if ($this->configFactory->get('rest.settings')->get('bc_entity_resource_permissions')) {
+ // The default Drupal 8.0.x and 8.1.x behavior.
+ return parent::permissions();
+ }
+ else {
+ // The default Drupal 8.2.x behavior.
+ return [];
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
protected function getBaseRoute($canonical_path, $method) {
$route = parent::getBaseRoute($canonical_path, $method);
$definition = $this->getPluginDefinition();