summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjibran2018-09-06 16:06:25 (GMT)
committerJibran Ijaz2018-09-06 16:06:25 (GMT)
commit21b8871a1c4f5396eac7cd304cb81e91692a4b6d (patch)
treeb756461bb3571653ecc197c774b5798909a42229
parent88e8319900a95a1e13164f703af786c1a17f427d (diff)
Issue #2970836 by jibran, das-peter, Berdir: Argument 3 passed to Drupal\hal\Normalizer\EntityReferenceItemNormalizer::__construct() must implement interface Drupal\Core\Entity\EntityTypeManagerInterface or be null8.x-1.6
-rw-r--r--src/DynamicEntityReferenceServiceProvider.php22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/DynamicEntityReferenceServiceProvider.php b/src/DynamicEntityReferenceServiceProvider.php
index cc6da32..b3f76f0 100644
--- a/src/DynamicEntityReferenceServiceProvider.php
+++ b/src/DynamicEntityReferenceServiceProvider.php
@@ -4,6 +4,7 @@ namespace Drupal\dynamic_entity_reference;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
+use Drupal\dynamic_entity_reference\Normalizer\DynamicEntityReferenceItemNormalizer;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
@@ -17,17 +18,20 @@ class DynamicEntityReferenceServiceProvider extends ServiceProviderBase {
*/
public function alter(ContainerBuilder $container) {
$modules = $container->getParameter('container.modules');
- if (isset($modules['rest']) && isset($modules['serialization']) && isset($modules['hal'])) {
+ if (isset($modules['hal'])) {
+ // Hal module is enabled, add our new normalizer for dynamic entity
+ // reference items.
+ // To avoid problems the arguments to
+ // \Drupal\hal\Normalizer\EntityReferenceItemNormalizer change, re-use
+ // the same constructor arguments and set the additional dependency
+ // with a setter method.
+ $parent_definition = $container->getDefinition('serializer.normalizer.entity_reference_item.hal');
+ $service_definition = new Definition(DynamicEntityReferenceItemNormalizer::class, $parent_definition->getArguments());
- // Add a normalizer service for dynamic_entity_reference fields.
- $service_definition = new Definition('Drupal\dynamic_entity_reference\Normalizer\DynamicEntityReferenceItemNormalizer', [
- new Reference('rest.link_manager'),
- new Reference('serializer.entity_resolver'),
- new Reference('module_handler'),
- ]);
// The priority must be higher than that of
- // serializer.normalizer.entity_reference.hal in hal.services.yml.
- $service_definition->addTag('normalizer', ['priority' => 20]);
+ // serializer.normalizer.entity_reference_item.hal in
+ // hal.services.yml.
+ $service_definition->addTag('normalizer', array('priority' => $parent_definition->getTags()['normalizer'][0]['priority'] + 1));
$container->setDefinition('serializer.normalizer.entity.dynamic_entity_reference_item.hal', $service_definition);
}