protected function ImceFM::getInitError in IMCE 8
Same name and namespace in other branches
- 8.2 src/ImceFM.php \Drupal\imce\ImceFM::getInitError()
Performs the initialization and returns the first error message.
1 call to ImceFM::getInitError()
- ImceFM::init in src/
ImceFM.php - Initializes the file manager.
File
- src/
ImceFM.php, line 133
Class
- ImceFM
- Imce File Manager.
Namespace
Drupal\imceCode
protected function getInitError() {
$conf =& $this->conf;
// Check configuration options.
$keys = [
'folders',
'root_uri',
];
foreach ($keys as $key) {
if (empty($conf[$key])) {
return $this
->t('Missing configuration %key.', [
'%key' => $key,
]);
}
}
// Check root.
$root_uri = $conf['root_uri'];
if (!is_dir($root_uri)) {
if (!mkdir($root_uri, $this
->getConf('chmod_directory', 0775), TRUE)) {
return $this
->t('Missing root folder.');
}
}
// Check and add predefined folders.
foreach ($conf['folders'] as $path => $folder_conf) {
$path = (string) $path;
$uri = $this
->createUri($path);
if (is_dir($uri) || mkdir($uri, $this
->getConf('chmod_directory', 0775), TRUE)) {
$this
->addFolder($path, $folder_conf);
}
else {
unset($conf['folders'][$path]);
}
}
if (!$conf['folders']) {
return $this
->t('No valid folder definitions found.');
}
// Check and set active folder if provided.
$path = $this
->getPost('active_path');
if (isset($path) && $path !== '') {
if ($folder = $this
->checkFolder($path)) {
$this->activeFolder = $folder;
// Remember active path.
if ($this->user
->isAuthenticated()) {
if (!isset($conf['folders'][$path]) || count($conf['folders']) > 1 || $folder
->getPermission('browse_subfolders')) {
$this->request
->getSession()
->set('imce_active_path', $path);
}
}
}
else {
return $this
->t('Invalid active folder path: %path.', [
'%path' => $path,
]);
}
}
return FALSE;
}