Problem/Motivation

Updated to Drupal 8.6.x and encountered the following error:
TypeError: Argument 3 passed to Drupal\hal\Normalizer\EntityReferenceItemNormalizer::__construct() must implement interface Drupal\Core\Entity\EntityTypeManagerInterface or be null, instance of Drupal\Core\Extension\ModuleHandler given, called in /var/www/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 270 in Drupal\hal\Normalizer\EntityReferenceItemNormalizer->__construct() (line 59 of core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php).

Proposed resolution

Seems like we need to adust DynamicEntityReferenceServiceProvider.
I'm not entirely sure but it looks like we need to pass in entity_type.manager instead module_handler.

Remaining tasks

Reviews needed.

User interface changes

None

API changes

None

Data model changes

None

Comments

das-peter created an issue. See original summary.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, for the fix.

berdir’s picture

That works, what I did in ERR is to copy the definition of the base class instead of hardcoding it and adding my custom addition as a setter method:

      // 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(EntityReferenceRevisionItemNormalizer::class, $parent_definition->getArguments());
      $service_definition->addMethodCall('setEntityTypeManager', [new Reference('entity_type.manager')]);

      // The priority must be higher than that of
      // 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_reference_revision_item', $service_definition);

Then it's as independant as possible from core. Of course now with 8.6, the additional setter isn't needed anymore, so I can remove that at some point but it also doesn't break because of it.

jibran’s picture

Status: Reviewed & tested by the community » Needs review
Related issues: +#2848878: Embed Paragraph Content in Normalized Parent Entities (REST)
StatusFileSize
new3.82 KB

Thanks, for the review and suggestion @Berdir. Implemented #3.

Status: Needs review » Needs work

The last submitted patch, 4: 2970836-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jibran’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new2.74 KB
jibran’s picture

StatusFileSize
new3.82 KB

Status: Needs review » Needs work

The last submitted patch, 8: 2970836-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

+++ b/src/Normalizer/DynamicEntityReferenceItemNormalizer.php
@@ -17,6 +18,26 @@ class DynamicEntityReferenceItemNormalizer extends EntityReferenceItemNormalizer
+   * The entity type manager.
+   *
+   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
+   */
+  protected $entityTypeManager;
+
+  /**
+   * Set the entity type manager.
+   *
+   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
+   *   The entity type manager.
+   *
+   * @todo remove this method once 8.5.x support is dropped.
+   */
+  public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager) {

Do you actaully need this stuff? You don't seem to be using this service yourself?

jibran’s picture

+++ b/src/DynamicEntityReferenceServiceProvider.php
@@ -17,17 +18,22 @@ class DynamicEntityReferenceServiceProvider extends ServiceProviderBase {
+      // @todo remove this once 8.5.x support is dropped.
+      $service_definition->addMethodCall('setEntityTypeManager', [new Reference('entity_type.manager')]);

Yes, we are not using it but how are we suppose to set ETM? Am I missing something?

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new2.58 KB
new2.38 KB
new2.14 KB

No, you are right we don't need that method parent constructor will work just fine.

The last submitted patch, 12: 2970836-12.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 12: 2970836-12-1.patch, failed testing. View results

alexpott’s picture

Priority: Normal » Critical

This is now breaking people's sites on 8.6.0 - see #2997848: Fatal error after updating to 8.6

jibran’s picture

The patches for both branches are ready just waiting for RTBC. I can commit them and create new release ASAP.

alexpott’s picture

@jibran I think here you could use \Symfony\Component\DependencyInjection\ChildDefinition - ie. https://symfony.com/doc/current/service_container/parent_services.html

But you'll still need to copy the tags so maybe the approach here is good. @Berdir?

  • jibran committed 21b8871 on 8.x-1.x
    Issue #2970836 by jibran, das-peter, Berdir: Argument 3 passed to Drupal...

  • jibran committed b9b1620 on 8.x-2.x
    Issue #2970836 by jibran, das-peter, Berdir: Argument 3 passed to Drupal...
jibran’s picture

Status: Needs work » Fixed

That's good enough. Thank, @alexpott, and @Berdir for the input.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.