public static File::preDelete(EntityStorageInterface $storage, array $entities)
Acts on entities before they are deleted and before hooks are invoked.
Used before the entities are deleted and before invoking the delete hook.
Parameters
\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.
\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.
Overrides Entity::preDelete
File
- core/modules/file/src/Entity/File.php, line 201
Class
- File
- Defines the file entity class.
Namespace
Drupal\file\Entity
Code
public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities); foreach ($entities as $entity) { // Delete all remaining references to this file. $file_usage = \Drupal::service('file.usage')->listUsage($entity); if (!empty($file_usage)) { foreach ($file_usage as $module => $usage) { \Drupal::service('file.usage')->delete($entity, $module); } } // Delete the actual file. Failures due to invalid files and files that // were already deleted are logged to watchdog but ignored, the // corresponding file entity will be deleted. file_unmanaged_delete($entity->getFileUri()); } }
Please login to continue.