Option to bring back the Assets sidebar folders view #13535
-
We recently upgraded a client's site and are getting some very negative feedback regarding the UX changes to the Assets index. They vastly preferred the old layout – being able to see the full sub-folder tree all at once rather than diving in and out to see the different levels. They are wondering if there is any possibility of an option to turn back on the folder display under each of the volumes in the sidebar.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I don’t think we should have an officially supported way of bringing subfolders back into the source list, given the reasons we changed it in the first place. But modules/plugins are free to modify element sources via Here’s how you could do it in Craft 4.5 (pending this change): use craft\base\Event;
use craft\elements\Asset;
use craft\events\RegisterElementSourcesEvent;
use craft\models\VolumeFolder;
// ...
private function attachEventHandlers(): void
{
Event::on(Asset::class, Asset::EVENT_REGISTER_SOURCES, function(RegisterElementSourcesEvent $event) {
$assetsService = Craft::$app->getAssets();
foreach ($event->sources as &$source) {
if (isset($source['data']['folder-id'])) {
$folder = $assetsService->getFolderById($source['data']['folder-id']);
if ($folder && !$folder->parentId) {
$subfolders = $assetsService->getAllDescendantFolders($folder, withParent: false, asTree: true);
$source['nested'] = $this->folders2sources($subfolders, $source);
}
}
}
});
}
private function folders2sources(array $folders, array $rootSource): array
{
return array_map(fn(VolumeFolder $folder) => [
'key' => "folder:$folder->uid",
'label' => $folder->name,
'hasThumbs' => true,
'criteria' => ['folderId' => $folder->id],
'defaultSort' => ['dateCreated', 'desc'],
'data' => [
'folder-id' => $folder->id,
'can-upload' => $rootSource['data']['can-upload'] ?? false,
'can-move-to' => $rootSource['data']['can-move-to'] ?? false,
'can-move-peer-files-to' => $rootSource['data']['can-move-peer-files-to'] ?? false,
'fs-type' => $rootSource['fs-type'] ?? null,
],
'nested' => $this->folders2sources($folder->getChildren(), $rootSource),
], $folders);
} Functionality for nested folders selected via the source list would be limited – you wouldn’t be able to rename/delete them or create new subfolders. Bringing those actions back would be more involved. |
Beta Was this translation helpful? Give feedback.
I don’t think we should have an officially supported way of bringing subfolders back into the source list, given the reasons we changed it in the first place. But modules/plugins are free to modify element sources via
EVENT_REGISTER_SOURCES
.Here’s how you could do it in Craft 4.5 (pending this change):