Same name and namespace in other branches
  1. 8.9.x core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php \Drupal\file\Plugin\Field\FieldType\FileFieldItemList::delete()
  2. 9 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 80

Class

FileFieldItemList
Represents a configurable entity file field.

Namespace

Drupal\file\Plugin\Field\FieldType

Code

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

  // If a translation is deleted only decrement the file usage by one. If the
  // default translation is deleted remove all file usages within this entity.
  $count = $entity
    ->isDefaultTranslation() ? 0 : 1;
  foreach ($this
    ->referencedEntities() as $file) {
    \Drupal::service('file.usage')
      ->delete($file, 'file', $entity
      ->getEntityTypeId(), $entity
      ->id(), $count);
  }
}