Problem/Motivation

I am using the Default Content Deploy module to export entities into code and I'm running into a normalization issue with taxonomy terms. I get the following error when exporting a root term (no parent).

Error: Call to a member function getEntityType() on null in Drupal\hal\Normalizer\EntityReferenceItemNormalizer->normalize() (line 86 of /var/www/html/dv13.openplus.ca/html/core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php)

I believe this is happening on the parent field, where it tries to call the getEntity() method on a target_id value of "0", then calls getEntityType() on NULL. This only happens when serializing using the hal_json format; using the json format works as expected.

Steps to reproduce

Use Drupal's serializer service against a root term using the hal_json format.

Example:

$term = \Drupal\taxonomy\Entity\Term::load('50');
$output = \Drupal::service('serializer')->serialize($term, 'hal_json');
dpm($output);

Comments

smulvih2 created an issue. See original summary.

smulvih2’s picture

Priority: Normal » Major

Setting this to major as the issue is triggering a PHP error through the UI and blocks the serialization of taxonomy terms in hal_json format.

smulvih2’s picture

Issue summary: View changes
smulvih2’s picture

Status: Active » Needs review
StatusFileSize
new913 bytes

Quick patch to get serialization working with hal_json format. Still need to test importing terms with this change. With hal_json the parent field renders [null], where with json format it renders [{"target_id":null}].

smulvih2’s picture

Status: Needs review » Closed (outdated)

I think my project is introducing a patch somewhere that caused hal_json serialization to break.

smulvih2’s picture

Status: Closed (outdated) » Closed (duplicate)
Related issues: +#2759397: Add recursion protection to EntityReferenceItem normalizers