You are here

public function Core::opUuid in IMCE 8

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

Operation handler: uuid.

File

src/Plugin/ImcePlugin/Core.php, line 59

Class

Core
Defines Imce Core plugin.

Namespace

Drupal\imce\Plugin\ImcePlugin

Code

public function opUuid(ImceFM $fm) {
  $items = $fm
    ->getSelection();
  if (!$items || !$fm
    ->validatePermissions($items, 'browse_files')) {
    return;
  }
  $uris = [];
  foreach ($items as $item) {
    if ($uri = $item
      ->getUri()) {
      $uris[$uri] = $item;
    }
  }
  if ($uris) {
    $files = \Drupal::entityTypeManager()
      ->getStorage('file')
      ->loadByProperties([
      'uri' => array_keys($uris),
    ]);
    $uuids = [];
    foreach ($files as $file) {
      $item = $uris[$file
        ->getFileUri()];
      $item->uuid = $file
        ->uuid();
      $uuids[$item
        ->getPath()] = $item->uuid;
    }
    $fm
      ->addResponse('uuids', $uuids);
  }
}