public function MediaDirectoriesController::directoryTree in Media Directories 2.x
Same name and namespace in other branches
- 8 modules/media_directories_ui/src/Controller/MediaDirectoriesController.php \Drupal\media_directories_ui\Controller\MediaDirectoriesController::directoryTree()
- 3.x modules/media_directories_ui/src/Controller/MediaDirectoriesController.php \Drupal\media_directories_ui\Controller\MediaDirectoriesController::directoryTree()
Return directory tree as JSON.
Return value
\Symfony\Component\HttpFoundation\JsonResponse A JSON response.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 string reference to 'MediaDirectoriesController::directoryTree'
- media_directories_ui.routing.yml in modules/
media_directories_ui/ media_directories_ui.routing.yml - modules/media_directories_ui/media_directories_ui.routing.yml
File
- modules/
media_directories_ui/ src/ Controller/ MediaDirectoriesController.php, line 135
Class
- MediaDirectoriesController
- Main controller class.
Namespace
Drupal\media_directories_ui\ControllerCode
public function directoryTree() {
$tree = [];
$this->termStorage = $this
->entityTypeManager()
->getStorage('taxonomy_term');
$terms = $this->termStorage
->loadTree($this->vocabularyId);
foreach ($terms as $term) {
$this
->buildTree($tree, $term, $this->vocabularyId);
}
$root_directory_name = $this
->t('Root');
if ($this
->config('media_directories.settings')
->get('all_files_in_root')) {
$root_directory_name .= ' (' . $this
->t('All directories') . ')';
}
$tree = [
[
'id' => 'dir-root',
'text' => $root_directory_name,
'state' => [
'opened' => TRUE,
'selected' => TRUE,
],
'a_attr' => [
'data-tid' => MEDIA_DIRECTORY_ROOT,
],
'children' => array_values($tree),
],
];
return new JsonResponse($tree);
}