Problem/Motivation

When trying to import menu_link_content entity via default content, getting below error:
InvalidArgumentException: Field uri is unknown. in core/lib/Drupal/Core/Entity/ContentEntityBase.php:509
After spending some time investigating the issue, found that Drupal\replication\Normalizer\LinkItemNormalizer breaks the structure of link field which is causing import issue.
Without replication module enabled, the menu links can be export/import without any issues.

Proposed resolution

Comments

vijaycs85 created an issue. See original summary.

andyf’s picture

Hi,

I'm seeing the same thing exporting a node with a link field using default_content and replication. I think I understand what's going on. From \Drupal\hal\Normalizer\FieldItemNormalizer::normalize():

    // The values are wrapped in an array, and then wrapped in another array
    // keyed by field name so that field items can be merged by the
    // FieldNormalizer. This is necessary for the EntityReferenceItemNormalizer
    // to be able to place values in the '_links' array.
    $field = $field_item->getParent();
    return [
      $field->getName() => [$this->normalizedFieldValues($field_item, $format, $context)],
    ];

Normally default_content relies on Drupal\hal\Normalizer\FieldItemNormalizer with a priority of 10 to handle links, but when replication's enabled, its \Drupal\replication\Normalizer\LinkItemNormalizer takes over with a priority of 40 and it doesn't return things in that particular format Hal is expecting. I'm brand new to replication, so could be missing something (: but is the solution just to prevent normalization of hal_json? (See attached patch.)

Thanks!

andyf’s picture

Status: Active » Needs review

  • jeqq committed cde921d on 8.x-1.x authored by AndyF
    Issue #2966785 by AndyF, vijaycs85: LinkItemNormalizer breaks importing...
jeqq’s picture

As Hal module does some special handling for that field type I think the fix makes sense.

Thanks @AndyF!

jeqq’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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