You are here

function field_collection_field_storage_config_delete in Field collection 8

Same name and namespace in other branches
  1. 8.3 field_collection.module \field_collection_field_storage_config_delete()

Implements hook_ENTITY_TYPE_delete() for field_storage_config.

Delete the field collection bundle when it's corrosponding field no longer exists in any bundle.

File

./field_collection.module, line 78
Module implementing field collection field type.

Code

function field_collection_field_storage_config_delete(EntityInterface $field) {
  if ($field
    ->getType() == 'field_collection') {

    // If this was called through field API bulk data deletion there may still
    // be a few field collection items from field data that hasn't been purged
    // yet.  Delete them here because Entity::delete() won't work after the
    // bundle is deleted.
    $field_collection_item_ids = \Drupal::entityQuery('field_collection_item')
      ->condition('field_name', $field
      ->getName())
      ->execute();
    $controller = \Drupal::entityTypeManager()
      ->getStorage('field_collection_item');
    $field_collection_items = $controller
      ->loadMultiple($field_collection_item_ids);
    $controller
      ->delete($field_collection_items);

    // Do the bundle delete.
    $field_collection_bundle = FieldCollection::load($field
      ->getName());
    $field_collection_bundle
      ->delete();
  }
}