public function removeEntityBundle($content_entity_type, $config_entity_type, $bundle, $field = 'type') {
    $content_removed = FALSE;
    if ($content_entity_type) {
      // Remove existing data of content entity.
      $query = $this->entityTypeManager
        ->getStorage($content_entity_type)
        ->getQuery('AND')
        ->condition($field, $bundle);

      $ids = $query->execute();
      $content_removed = $this->removeContent($content_entity_type, $config_entity_type, $bundle, $ids);
    }

    if ($config_entity_type && $content_removed) {
      // Remove bundle.
      $config_entity_type_bundle = $this->entityTypeManager
        ->getStorage($config_entity_type)
        ->load($bundle);
      if ($config_entity_type_bundle) {
        try {
          $config_entity_type_bundle->delete();
        }
        catch (\Exception $e) {
          watchdog_exception('openy', $e, "Error! Can't delete config entity 
          @config_entity_type bundle <b>@bundle</b>, please @remove.", [
            '@config_entity_type' => $config_entity_type,
            '@bundle' => $bundle,
            '@remove' => $this->getLink($config_entity_type, 'remove it manually', $bundle),
          ], RfcLogLevel::NOTICE);
        }
      }
    }
  }
public function removeEntityBundle($content_entity_type, $config_entity_type, $bundle, $field = 'type') {
    $content_removed = FALSE;
    if ($content_entity_type) {
      // Remove existing data of content entity.
      $query = $this->entityTypeManager
        ->getStorage($content_entity_type)
        ->getQuery('AND')
        ->condition($field, $bundle);

      $ids = $query->execute();
      $content_removed = $this->removeContent($content_entity_type, $config_entity_type, $bundle, $ids);
    }

    if ($config_entity_type && $content_removed) {
      // Remove bundle.
      $config_entity_type_bundle = $this->entityTypeManager
        ->getStorage($config_entity_type)
        ->load($bundle);
      if ($config_entity_type_bundle) {
        try {
          $config_entity_type_bundle->delete();
        }
        catch (\Exception $e) {
          watchdog_exception('openy', $e, "Error! Can't delete config entity 
          @config_entity_type bundle <b>@bundle</b>, please @remove.", [
            '@config_entity_type' => $config_entity_type,
            '@bundle' => $bundle,
            '@remove' => $this->getLink($config_entity_type, 'remove it manually', $bundle),
          ], RfcLogLevel::NOTICE);
        }
      }
    }
  }
public function removeEntityBundle ( $ content_entity_type , $ config_entity_type , $ bundle , $ field = 'type' ) { $ content_removed = FALSE ; if ( $ content_entity_type ) { // Remove existing data of content entity. $ query = $ this -> entityTypeManager -> getStorage ( $ content_entity_type ) -> getQuery ( 'AND' ) -> condition ( $ field , $ bundle ) ; $ ids = $ query -> execute ( ) ; $ content_removed = $ this -> removeContent ( $ content_entity_type , $ config_entity_type , $ bundle , $ ids ) ; } if ( $ config_entity_type && $ content_removed ) { // Remove bundle. $ config_entity_type_bundle = $ this -> entityTypeManager -> getStorage ( $ config_entity_type ) -> load ( $ bundle ) ; if ( $ config_entity_type_bundle ) { try { $ config_entity_type_bundle -> delete ( ) ; } catch ( \ Exception $ e ) { watchdog_exception ( 'openy' , $ e , "Error! Can't delete config entity 
          @config_entity_type bundle <b>@bundle</b>, please @remove." , [ '@config_entity_type' => $ config_entity_type , '@bundle' => $ bundle , '@remove' => $ this -> getLink ( $ config_entity_type , 'remove it manually' , $ bundle ) , ] , RfcLogLevel :: NOTICE ) ; } } } }
Remove Entity bundle.

This is helper function for modules uninstall with correct bundle
deleting and content cleanup.

@param string $content_entity_type
Content entity type (node, block_content, paragraph, etc.)
@param string $config_entity_type
Config entity type (node_type, block_content_type, paragraphs_type, etc.)
@param string $bundle
Entity bundle machine name.
@param string $field
Content entity field name that contain reference to bundle.

@throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
@throws \Drupal\Core\Entity\EntityStorageException
Remove Entity bundle .