You are here

public function Newfolder::opNewfolder in IMCE 8

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

Operation handler: newfolder.

File

src/Plugin/ImcePlugin/Newfolder.php, line 44

Class

Newfolder
Defines Imce New Folder plugin.

Namespace

Drupal\imce\Plugin\ImcePlugin

Code

public function opNewfolder(ImceFM $fm) {
  $folder = $fm->activeFolder;
  if (!$folder || !$folder
    ->getPermission('create_subfolders')) {
    return;
  }

  // Create folder.
  $name = $fm
    ->getPost('newfolder');
  if (is_string($name) && $fm
    ->validateFileName($name)) {

    // Check existence.
    $uri = Imce::joinPaths($folder
      ->getUri(), $name);
    if (file_exists($uri)) {
      $fm
        ->setMessage($this
        ->t('%filename already exists.', [
        '%filename' => $name,
      ]));
    }
    elseif (mkdir($uri, $fm
      ->getConf('chmod_directory', 0775))) {
      $folder
        ->addSubfolder($name)
        ->addToJs();
    }
  }
}