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.
By bogeyman on
Hi,
I want to change my entity_reference field from autocomplete to dropdown list (select). So far I try another method by overriding in buildForm method in my form class but it produce the error (Error: Cannot unset string offsets in Drupal\Core\Field\WidgetBase->extractFormValues()). Here is my code.
$form['account_group'] = [
'#title' => $this->t('Account group'),
'#description' => $this->t('The account group.'),
'#type' => 'select',
'#options' => $options,
'#required' => TRUE,
'#default_value' => $current_account_group,
];
I know that's not the good practice. What is the best way to do it? Maybe I should do it in my baseFieldDefinitions method. But I have no idea how to set it.
Comments
Arghh.. I was thinking too
Arghh.. I was thinking too complicated. I can change it in form display :).