Created
June 1, 2020 14:56
-
-
Save lcube45/4364f8ae3e0a10a830ea33317b6606f6 to your computer and use it in GitHub Desktop.
Drupal 8 - hook update - installEntityType/uninstallEntityType
This file contains hidden or 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
<?php | |
/** | |
* Update- Create your_entity_name entity. | |
*/ | |
function my_module_update_8001() { | |
//check if the table exists first. If not, then create the entity. | |
if(!db_table_exists('your_entity_name')) { | |
\Drupal::entityTypeManager()->clearCachedDefinitions(); | |
\Drupal::entityDefinitionUpdateManager() | |
->installEntityType(\Drupal::entityTypeManager()->getDefinition('your_entity_name')); | |
} | |
else { | |
return 'your_entity_name entity already exists'; | |
} | |
} | |
/** | |
* Uninstall- Create your_entity_name entity. | |
*/ | |
function my_module_update_8003() { | |
//check if the table exists first. If not, then create the entity. | |
if(db_table_exists('your_entity_name')) { | |
\Drupal::entityTypeManager()->clearCachedDefinitions(); | |
\Drupal::entityDefinitionUpdateManager() | |
->uninstallEntityType(\Drupal::entityTypeManager()->getDefinition('faq_answer_entity')); | |
} | |
else { | |
return 'faq_answer_entity entity do not exist'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since Drupal 8.7.x, drush entup and automatic entity updates have been removed.
2 ways :