I created a custom entity with drupal generate:entity:content
.
I am adding fields in the baseFieldDefinitions
method of the entity class.
Below is what drupal console generates by default for the name
field.
Where I can find a list of all possible type
values for ->setDisplayOptions('form')
. For example, the field below uses string_textfield
.
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
...
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the entity.'))
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -4,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);