Value is not a valid entity error when referenced entity is not available

Created on 19 April 2024, 10 months ago

Problem/Motivation

When referenced entity is not available on DependencyStack or locally then import stops because value passed to entity reference field is incorrect.

Steps to reproduce

  • Export node with reference to term
  • Remove term entity from Dependency stack
  • Import CDF from ACH

Proposed resolution

  public function setValue($value, $notify = TRUE) {
    unset($this->target);
    unset($this->id);

    // Both the entity ID and the entity object may be passed as value. The
    // reference may also be unset by passing NULL as value.
    if (!isset($value)) {
      $this->target = NULL;
    }
    elseif ($value instanceof EntityInterface) {
      $this->target = $value->getTypedData();
    }
    elseif (!is_scalar($value) || $this->getTargetDefinition()->getEntityTypeId() === NULL) {
      throw new \InvalidArgumentException('Value is not a valid entity.');
    }
    else {
      $this->id = $value;
    }
    // Notify the parent of any changes.
    if ($notify && isset($this->parent)) {
      $this->parent->onChange($this->name);
    }
  }

EntityReference Data Type allows only for scalar but, Unserialize Plugin for EntityReference field in line 68, sets the empty array for target_id. We should remove this line and continue to the next value.

            if (!$entity) {
              $values[$langcode][$event->getFieldName()][]['target_id'] = [];
              $this->log($item);
              continue;
            }

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.4

Component

Code

Created by

🇵🇱Poland lamp5 Rzeszow

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024