Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295606

\Drupal\hal\Normalizer\EntityReferenceItemNormalizer::normalize() tries to normalize entities that don't exist

$
0
0

Problem/Motivation

In \Drupal\hal\Normalizer\EntityReferenceItemNormalizer::normalize() it's possible that we're dealing with an entity that does not exist. I.e $target_entity = $field_item->get('entity')->getValue(); returns NULL. In PHP versions prior to 7.4 we've soldiered on and returned an array anyways.

#3086374: Make Drupal 8 & 9 compatible with PHP 7.4 fixes it to continue the same behaviour as before but this is maintaining a broken code path. Once $target_entity is null there is no point calling $embedded = $this->serializer->normalize($target_entity, $format, $context); and the return value of

    return [
      '_links' => [
        $field_uri => [$link],
      ],
      '_embedded' => [
        $field_uri => [$embedded],
      ],
    ];

Is probably meaningless because $link is an array with 1 item - a langocde and $embedded is NULL.

To reproduce the error remove the fix from #3086374: Make Drupal 8 & 9 compatible with PHP 7.4 and run Drupal\Tests\node\Functional\Hal\NodeHalJsonAnonTest

Proposed resolution

Fix more appropriately.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 295606


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>