Goal:
Add a database index to a 'created' field.
Given:
There is a custom entity with a base field created
.
The field is stored the entity table.
Field source code of the created
field:
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'))
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'timestamp',
'weight' => 3,
'settings' => [
'date_format' => 'medium',
'custom_date_format' => '',
'timezone' => '',
],
])
->setDisplayConfigurable('view', TRUE);
What I researched:
I have not found a way to add index using the \Drupal\Core\Field\BaseFieldDefinition()
.
As I understand indexes are defined in a @FieldType
plugin. The created
field is implemented via the \Drupal\Core\Field\Plugin\Field\FieldType\TimestampItem()
plugin and obviously does not have have indexes there.
P.S. I know, that I can write an updatescript to add an index to the table manually.
@FieldType
created_indexed
.created
field and only set the new class via the setClass method.