You are here

public function FileFieldItemList::delete in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php \Drupal\file\Plugin\Field\FieldType\FileFieldItemList::delete()

Defines custom delete behavior for field values.

This method is called during the process of deleting an entity, just before values are deleted from storage.

Overrides FieldItemList::delete

File

core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php, line 83
Contains \Drupal\file\Plugin\Field\FieldType\FileFieldItemList.

Class

FileFieldItemList
Represents a configurable entity file field.

Namespace

Drupal\file\Plugin\Field\FieldType

Code

public function delete() {
  parent::delete();
  $entity = $this
    ->getEntity();

  // Delete all file usages within this entity.
  foreach ($this
    ->referencedEntities() as $file) {
    \Drupal::service('file.usage')
      ->delete($file, 'file', $entity
      ->getEntityTypeId(), $entity
      ->id(), 0);
  }
}