I have defined a custom entity type "Event" and I want a field on it called "Attendees" which should allow the user to enter multiple attendees.
I have defined the field thus:
$fields['attendees'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Attendees')) ->setDescription(t('People attending this event.')) ->setSetting('target_type', 'oc_actor') ->setSetting('handler', 'default') ->setTranslatable(TRUE) ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) ->setDisplayOptions('view', [ 'type' => 'string', 'weight' => 50, ]) ->setDisplayOptions('form', [ 'type' => 'entity_reference_autocomplete_tags', 'weight' => 50, ]) ->setRequired(FALSE);
However, the resulting field does not have unlimited cardinality. It only allows the user to enter one attendee. Compare and contrast with the "Test" field that I added beneath it using the GUI:
I have done a fresh install of the whole site since I last touched this code so it is not a matter of needing to add an update hook or clear the cache or anything like that.
Any ideas?