You are here

public function FileUrlFieldItemList::delete in File URL 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldType/FileUrlFieldItemList.php \Drupal\file_url\Plugin\Field\FieldType\FileUrlFieldItemList::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

src/Plugin/Field/FieldType/FileUrlFieldItemList.php, line 140

Class

FileUrlFieldItemList
Represents a configurable entity file URL field.

Namespace

Drupal\file_url\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) {
    if (!FileUrlHandler::isRemote($file)) {
      \Drupal::service('file.usage')
        ->delete($file, 'file', $entity
        ->getEntityTypeId(), $entity
        ->id(), $count);
    }
  }
}