You are here

function opigno_calendar_event_opigno_calendar_event_type_delete in Opigno calendar event 8

Same name and namespace in other branches
  1. 3.x opigno_calendar_event.module \opigno_calendar_event_opigno_calendar_event_type_delete()

Implements hook_ENTITY_TYPE_delete().

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

./opigno_calendar_event.module, line 59
Main file for the "Calendar event" module.

Code

function opigno_calendar_event_opigno_calendar_event_type_delete(ConfigEntityInterface $type) {

  // @todo Clean up this once
  //   https://www.drupal.org/project/drupal/issues/2346013 is fixed.
  $entity_type_id = CalendarEventInterface::ENTITY_TYPE_ID;
  $entity_type = \Drupal::entityTypeManager()
    ->getDefinition($entity_type_id);
  $all_bundle_storage_definitions = CalendarEvent::storageFieldDefinitions($entity_type);
  $field_name = CalendarEvent::getDateFieldName($type);
  if (!isset($all_bundle_storage_definitions[$field_name])) {

    /** @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $last_installed */
    $last_installed = \Drupal::service('entity.last_installed_schema.repository');
    $storage_definitions = $last_installed
      ->getLastInstalledFieldStorageDefinitions($entity_type_id);
    if (isset($storage_definitions[$field_name])) {
      \Drupal::entityDefinitionUpdateManager()
        ->uninstallFieldStorageDefinition($storage_definitions[$field_name]);
    }
  }
}