summaryrefslogtreecommitdiffstats
path: root/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
diff options
context:
space:
mode:
authorAlex Pott2016-06-19 14:41:10 +0100
committerAlex Pott2016-06-19 14:41:10 +0100
commit871da5e4f723b5b1928956c495a0f148e4cbbaff (patch)
tree3f6e42c521915dd5c71c9077264ae144c1bbbbb8 /core/modules/rest/src/Plugin/rest/resource/EntityResource.php
parent9bb1c3691c257f1a89c7545da9f1ec2aaa7c4dc9 (diff)
Issue #2308745 by Alumei, dawehner, Wim Leers, larowlan, Arla, alexpott, g.oechsler, R.Muilwijk, Berdir, catch, klausi, clemens.tolboom, MattA, Crell: Remove rest.settings.yml, use rest_resource config entities
Diffstat (limited to 'core/modules/rest/src/Plugin/rest/resource/EntityResource.php')
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php35
1 files changed, 22 insertions, 13 deletions
diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
index b01033f..7e620df 100644
--- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
@@ -2,6 +2,7 @@
namespace Drupal\rest\Plugin\rest\resource;
+use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
@@ -9,9 +10,9 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
-use Drupal\rest\ModifiedResourceResponse;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\rest\ModifiedResourceResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -32,14 +33,14 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
* }
* )
*/
-class EntityResource extends ResourceBase {
+class EntityResource extends ResourceBase implements DependentPluginInterface {
/**
- * The entity type manager.
+ * The entity type targeted by this resource.
*
- * @var \Drupal\Core\Entity\EntityTypeManagerInterface
+ * @var \Drupal\Core\Entity\EntityTypeInterface
*/
- protected $entityTypeManager;
+ protected $entityType;
/**
* Constructs a Drupal\rest\Plugin\rest\resource\EntityResource object.
@@ -50,16 +51,16 @@ class EntityResource extends ResourceBase {
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
+ * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
+ * The entity type manager
* @param array $serializer_formats
* The available serialization formats.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
- * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
- * The entity type manager.
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, array $serializer_formats, LoggerInterface $logger, EntityTypeManagerInterface $entity_type_manager) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, $serializer_formats, LoggerInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger);
- $this->entityTypeManager = $entity_type_manager;
+ $this->entityType = $entity_type_manager->getDefinition($plugin_definition['entity_type']);
}
/**
@@ -70,9 +71,9 @@ class EntityResource extends ResourceBase {
$configuration,
$plugin_id,
$plugin_definition,
+ $container->get('entity_type.manager'),
$container->getParameter('serializer.formats'),
- $container->get('logger.factory')->get('rest'),
- $container->get('entity_type.manager')
+ $container->get('logger.factory')->get('rest')
);
}
@@ -331,8 +332,16 @@ class EntityResource extends ResourceBase {
* TRUE if the entity is a Config Entity, FALSE otherwise.
*/
protected function isConfigEntityResource() {
- $entity_type_id = $this->getPluginDefinition()['entity_type'];
- return $this->entityTypeManager->getDefinition($entity_type_id) instanceof ConfigEntityType;
+ return $this->entityType instanceof ConfigEntityType;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function calculateDependencies() {
+ if (isset($this->entityType)) {
+ return ['module' => [$this->entityType->getProvider()]];
+ }
}
}