You are here

public static function Delete::deleteFileUri in IMCE 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/ImcePlugin/Delete.php \Drupal\imce\Plugin\ImcePlugin\Delete::deleteFileUri()

Deletes a file by uri.

2 calls to Delete::deleteFileUri()
Delete::deleteFolderUri in src/Plugin/ImcePlugin/Delete.php
Deletes a folder by uri.
Delete::deleteItems in src/Plugin/ImcePlugin/Delete.php
Deletes a list of imce items and returns succeeded ones.

File

src/Plugin/ImcePlugin/Delete.php, line 82

Class

Delete
Defines Imce Delete plugin.

Namespace

Drupal\imce\Plugin\ImcePlugin

Code

public static function deleteFileUri($uri, $ignore_usage = FALSE) {

  // Managed file.
  if ($file = Imce::getFileEntity($uri)) {
    if (!$ignore_usage && ($usage = \Drupal::service('file.usage')
      ->listUsage($file))) {
      unset($usage['imce']);
      if ($usage) {
        \Drupal::messenger()
          ->addMessage(t('%filename is in use by another application.', [
          '%filename' => $file
            ->getFilename(),
        ]), 'error');
        return FALSE;
      }
    }
    $file
      ->delete();
    return TRUE;
  }

  // Unmanaged file.
  return \Drupal::service('file_system')
    ->delete($uri);
}