I'm creating a custom entity type, that has the following base field (defined in a class that extends ContentEntityBase)
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['recipient_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Recipient(s)'))
->setDescription(t('The recipient(s)'))
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'entity_reference_label',
'weight' => -3,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => 60,
'autocomplete_type' => 'tags',
'placeholder' => '',
),
'weight' => -3,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
}
I've set the field to have unlimited cardinality. I'm trying to create the getters and setters for this field, however I'm not finding any examples of entity types with multiple values.
I need to create the following getters and setters:
// Add a single recipient to the entity
public function setRecipient()
// retrieve all recipients for the entity
public function getRecipients()
Does anyone have an example of how to set up these functions to work with a multiple value field?