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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

That'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?

seanB’s picture

I 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.

jsacksick’s picture

Status: Needs review » Fixed

Committed, thanks.

  • jsacksick committed bfca7e6 on 7.x-2.x authored by seanB
    Issue #2441973 by seanB: Allow setting default values via $form_state.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jonas139’s picture

Status: Closed (fixed) » Needs review
FileSize
960 bytes

I'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!