You are here

function image_field_caption_entity_delete in Image Field Caption 8

Implements hook_entity_delete().

File

./image_field_caption.module, line 267
Provides a caption textarea for image fields.

Code

function image_field_caption_entity_delete(EntityInterface $entity) {
  $imageCaption = Drupal::service('image_field_caption.storage');

  // For a fieldable entity.
  if ($entity instanceof FieldableEntityInterface) {

    // Get the field names of all image fields.
    $field_names = _image_field_caption_get_image_field_names($entity);
    foreach ($field_names as $field_name) {

      // Delete the caption associated to this field.
      $imageCaption
        ->deleteCaption($entity
        ->getEntityTypeId(), $entity
        ->bundle(), $field_name, $entity
        ->id(), $entity
        ->language()
        ->getId());

      // Delete the caption revisions associated to this field.

      /*
      $imageCaption->deleteCaptionRevisions($entity->getEntityTypeId(), $entity->bundle(), $field_name, $entity->id(), $entity->language()->getId());
      */
    }
  }
}