Home > Mobile >  Change folder sorting in wysiwyg Magento 2
Change folder sorting in wysiwyg Magento 2

Time:10-05

Coding to create a store with Magento I found a 'problem' I would like to solve.

Whenever I open the file system in Magento using Wysiwyg, the folders are not sorted at all.

Find here an example enter image description here

I would like to have the folders sorted by name ASC. I tried modiying the Storage class by creating a preference of vendor\magento\module-cms\Model\Wysiwyg\Images\Storage.php

and it actually works for images inside but not for folders!

As you can see images are sorted but folders

My big question is, how can I sort this folder collection by name? Where can I find the files for this changes?

Thanks!

CodePudding user response:

The \Magento\Cms\Model\Wysiwyg\Images\Storage class has method getDirsCollection

Extend it by calling setOrder setter


$collection = $this->getCollection($path)
    ->setCollectDirs(true)
    ->setCollectFiles(false)
    ->setCollectRecursively(false)
    // ===> setter <===
    ->setOrder(
        'name',
        \Magento\Framework\Data\Collection::SORT_ORDER_ASC
    )
;
  • Related