Created
December 1, 2023 14:14
-
-
Save klaasvw/43b73dc42be4d85553f44024b5831d5a to your computer and use it in GitHub Desktop.
Add base field to existing entity type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add the entity_type field_name field. | |
*/ | |
function module_name_update_9001() { | |
$type_manager = \Drupal::entityTypeManager(); | |
$type_manager->clearCachedDefinitions(); | |
$entity_type = $type_manager->getDefinition('entity_type'); | |
$storage_definition = EntityTypeClass::baseFieldDefinitions($entity_type); | |
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition( | |
'field_name', | |
$entity_type->id(), | |
'entity_type', | |
$storage_definition['field_name'] | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment