Skip to content

Instantly share code, notes, and snippets.

@nguyenthanhxuan
Created February 29, 2024 08:32
Show Gist options
  • Save nguyenthanhxuan/f60fc662a59c6359417bb3db42da0955 to your computer and use it in GitHub Desktop.
Save nguyenthanhxuan/f60fc662a59c6359417bb3db42da0955 to your computer and use it in GitHub Desktop.
Create a New Content Entity During Module Update
<?php
use Drupal\Core\Database\Database;
/**
* Create the entity table if it does not exist.
*/
function twist_opsf_update_9001(){
//check if the table exists first. If not, then create the entity.
if(!Database::getConnection()->schema()->tableExists('maestro_process_status')) {
\Drupal::entityTypeManager()->clearCachedDefinitions();
\Drupal::entityDefinitionUpdateManager()
->installEntityType(\Drupal::entityTypeManager()->getDefinition('maestro_process_status'));
} else {
return 'Process Status entity already exists';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment