Do you want to know how to Drupal?

Let's Drupal

Entity type

How to list content entities in Drupal 9?

If you need to get a list of content entitles in your Drupal 9 website for example for drop down on the configuration page you can use the next code snippet
use Drupal\Core\Entity\ContentEntityType;

$content_entities = [];

// Get all entities definitions.
$entity_type_definations = \Drupal::entityTypeManager()->getDefinitions();

foreach ($entity_type_definations as $definition) {
  // Check that definition is instance of ContentEntityType
  if ($definition instanceof ContentEntityType) {
    $content_entities [] = $definition;
  }
}

 


How to remove (uninstall) entity type in Drupal 8?

If we don't need some entity type anymore we can easily remove it.
// Get update manager.
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
// Get entity type.
$entity_type = $definition_update_manager->getEntityType('your_entity_type_id');
if ($entity_type ) {
    // Uninstall entity type.
    $definition_update_manager->uninstallEntityType($entity_type);
}