Below is my code for the view. I have tried multiple = true, multiple_values=true, multiple = multiple. None have worked.

->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => 0,
    'settings' => [
        'match_operator' => 'CONTAINS',
        'size' => '60',
        'autocomplete_type' => 'tags',
        'placeholder' => '',
    ],
])
up vote 0 down vote accepted

The options_select widget will automatically be multi-select if the cardinality of the field is multiple. Make sure your field is created as such, e.g.

use Drupal\Core\Field\FieldStorageDefinitionInterface;

...

$fields['foo'] = BaseFieldDefinition::create('entity_reference')
  ...
  ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
  ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => 0,
    'settings' => [],
  ])
  ...

Incidentally, options_select has no settings, so you can provide an empty array instead of the autocomplete settings you're currently using.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.