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);
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | core-fix-hal-json-serialization-root-terms-3302106-4.patch | 913 bytes | smulvih2 |
Comments
Comment #2
smulvih2Setting 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.
Comment #3
smulvih2Comment #4
smulvih2Quick 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}].Comment #5
smulvih2I think my project is introducing a patch somewhere that caused hal_json serialization to break.
Comment #6
smulvih2