Skip to content

Instantly share code, notes, and snippets.

@twfahey1
Created December 14, 2022 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twfahey1/045151f275db7492f0b811fa927b2c1c to your computer and use it in GitHub Desktop.
Save twfahey1/045151f275db7492f0b811fa927b2c1c to your computer and use it in GitHub Desktop.
Creating a new content entity in an existing enabled module

Let's say you just generated a content entity with drush:

drush generate entity:content

(... you go through the prompts, and the entity is created in an existing, enabled module)

In the module's .install file, add a hook_update_N(), for example if you previously called your entity a_super_cool_entity

/**
 * Install new entity type called a_super_cool_entity
 */
function backstopjs_tools_update_8001() {
  // Install the new a_super_cool_entity entity type.
  $update_manager = \Drupal::entityDefinitionUpdateManager();
  $update_manager->installEntityType(\Drupal::entityTypeManager()->getDefinition('a_super_cool_entity'));

}

And run drush updb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment