Add a database index to a 'created' field.
There is a custom entity with a base field
The field is stored the entity table.
Field source code of the
$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
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.