After debugging, I found the following issue: when we use an entity_reference field (with an entity browser for selection), we are not able to save default values properly:
$field_value, in our case looks like [ 'target_id' => 'media:123' ] where "123" is the mid of the media item. This is not valid and throws inside "PrimitiveTypeConstraintValidator", since this is supposed to be an integer, but 'media:123' is a string, but '123' would be valid.
if (isset($field_value['target_id']) && is_array($field_value['target_id'])) {
$field_value = $field_value['target_id'];
}
I think this should handle this case, but $field_value['target_id'] is not an array and would still contain 'media:123'
Is there a special use-case, we are missing to handle references?
Comments
Comment #2
drcolossos commentedJust a quick heads-up:
If I add
after your "odd term structure" fix, everything works as expected for the reference.
Comment #3
pratik_kamblePatch to fix the issue related to the media reference entities.
Comment #4
b_sharpe commentedThis was causing me undefined index errors when the handler was a single item (i.e. views, layout_library), also when media was used but the handler was not default:media the structure was different.
I've updated the patch to put in these checks, if someone wants to validate I will put this into next release.
Comment #5
ricardochefigueroa commented#3 This patch worked for me. Thanks.
Comment #6
Lal_Moving the issues to RTBC as the patch solves the issues.... Adding the screen shots.
Comment #7
Lal_Comment #9
b_sharpe commentedThanks all, committed!
Comment #11
scotwith1tFor me, this still only works with the autocomplete widget and does not set the default value on existing content when Media Library is set as the widget...I had to set to use autocomplete, resave to get the batch to run again, then switch back to Media Library for the correct/desired UX.
Comment #12
b_sharpe commentedWidget submission format is definitely an issue, unfortunately I'm not sure how to remedy short of creating a case for each widget individually. For core that's likely ok and minimal, but contrib widgets will likely never be supported.