0

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' => '',
    ],
])
1

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.

  • while adding FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, I am getting error like Base table or view not found: 1146 Table 'temp.modulename__foo' doesn't exist, @Clive any idea about this? – Mukunda Bhatta Aug 22 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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