Newfolder.php in IMCE 8.2
File
src/Plugin/ImcePlugin/Newfolder.php
View source
<?php
namespace Drupal\imce\Plugin\ImcePlugin;
use Drupal\imce\Imce;
use Drupal\imce\ImcePluginBase;
use Drupal\imce\ImceFM;
class Newfolder extends ImcePluginBase {
public function permissionInfo() {
return [
'create_subfolders' => $this
->t('Create subfolders'),
];
}
public function buildPage(array &$page, ImceFM $fm) {
if ($fm
->hasPermission('create_subfolders')) {
$page['#attached']['library'][] = 'imce/drupal.imce.newfolder';
}
}
public function opNewfolder(ImceFM $fm) {
$folder = $fm->activeFolder;
if (!$folder || !$folder
->getPermission('create_subfolders')) {
return;
}
$name = $fm
->getPost('newfolder');
if (is_string($name) && $fm
->validateFileName($name)) {
$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();
}
}
}
}