You are here

public static function Upload::delete in Lightning Media 8.3

Same name and namespace in other branches
  1. 8.4 src/Element/Upload.php \Drupal\lightning_media\Element\Upload::delete()
  2. 8 src/Element/Upload.php \Drupal\lightning_media\Element\Upload::delete()
  3. 8.2 src/Element/Upload.php \Drupal\lightning_media\Element\Upload::delete()

Deletes the file referenced by the element.

Parameters

array $element: The element. If set, its value should be a file entity ID.

2 calls to Upload::delete()
InteractiveUpload::remove in src/Element/InteractiveUpload.php
Handles form submission when the Remove button is clicked.
Upload::validate in src/Element/Upload.php
Validates the uploaded file.

File

src/Element/Upload.php, line 64

Class

Upload
A form element to handle file uploads.

Namespace

Drupal\lightning_media\Element

Code

public static function delete(array $element) {
  if ($element['#value']) {
    $file = File::load($element['#value']);
    $file
      ->delete();

    // Clean up the file system if needed.
    $uri = $file
      ->getFileUri();
    if (file_exists($uri)) {
      \Drupal::service('file_system')
        ->unlink($uri);
    }
  }
}