Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
How would you set a default value (i.e a value that is already selected) in the widget using a hook_form_alter() on a node form ?
The way I previously used for Entity Reference - Auto complete OR Select list widget - do not work.
Thanks
Comment | File | Size | Author |
---|---|---|---|
#6 | entityreference_view_widget-extra_check_on_none.patch | 960 bytes | jonas139 |
#2 | entityreference_view_widget-set_default_values-2441973-2.patch | 659 bytes | seanB |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedThat's a good question - I think entityreference_view_widget_rows($entity_ids, $settings) ist only for internal use.
Is there a clean way to set default values?
Comment #2
seanBI created a patch to allow settings default values through the form_state. This is also needed for entityconnect to add form values.
The entityconnect module sets the values with $form_state['input']. If we use this we can also solve the integration with this module.
Comment #3
jsacksick CreditAttribution: jsacksick commentedCommitted, thanks.
Comment #6
jonas139 CreditAttribution: jonas139 at iO commentedI'm having some problems with the new release of Entity Reference View Widget and Paragraphs.
I have a paragraph bundle with an entity reference view but when I want to edit a paragraph on an existing node I'm getting
'Warning: Invalid argument supplied for foreach() in entityreference_view_widget_field_widget_form()'
in my watchdog.
I've narrowed the error down to the patch in this issue.
The problem is that the referenced field in the $form_state['input'] is not empty but has '_none' as value.
I've added a small patch but I think it's not the best solution so any help is appreciated!