asulibraries / islandora-repo

ASU Digital Repository on Islandora
GNU General Public License v2.0
4 stars 4 forks source link

PHP Error: User error: "target_id" is an invalid render array #549

Closed seth-shaw-asu closed 2 years ago

seth-shaw-asu commented 2 years ago

The Drupal logs show several instances of 'User error: "target_id" is an invalid render array' on OAI-PMH GetRecord and ListRecords requests. E.g. https://keep.lib.asu.edu/oai/request?identifier=oai%3Akeep.lib.asu.edu%3Anode-133403&metadataPrefix=oai_dc&verb=GetRecord.

For some unknown reason, these records are loading in the rest_oai_pmh with a copyright field with an erroneous target_id array reference to a '0' entity, which doesn't exist. (I'm not able to replicate seeing the incorrectly set field item using php:cli or the web-editor.) This target_id array gets passed to the JSON-LD EntityReferenceConverter::linkedFieldPassthrough() which, as written, sends the value right back because it can't load the entity. Now, DublinCoreRdf::transformRecord() will check target_id arrays and return the target_id value if it can't load the entity, but not if it was sent through a converter first. This results in our target_id array being past as-is to the Twig rendering which then chokes on it.

The simplest solution is probably to have EntityReferenceConverter::linkedFieldPassthrough() return either the target_id value (as transformRecord() does) or an empty value. We should probably also have transformRecord() NOT add an empty value to the elements render array.

seth-shaw-asu commented 2 years ago

Adding to milestone, although I'm sure that simply adding the PR patch to the composer.json will resolve this.

seth-shaw-asu commented 2 years ago

Resolved with https://github.com/asulibraries/islandora-repo/commit/b6ab306a9b3753b1c5cb411b19f0cc694ea2c83b, although hopefully the JSON-LD PR will be merged soon and make the composer patch obsolete.