Skip to content

Commit 84e590c

Browse files
MC-41854: Page builder gallery load issue
1 parent ad08ccf commit 84e590c

File tree

1 file changed

+32
-1
lines changed
  • app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images

1 file changed

+32
-1
lines changed

app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Tree.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Cms\Block\Adminhtml\Wysiwyg\Images;
77

8+
use Magento\Framework\Filesystem;
9+
810
/**
911
* Directory tree renderer for Cms Wysiwyg Images
1012
*
@@ -32,25 +34,33 @@ class Tree extends \Magento\Backend\Block\Template
3234
*/
3335
private $serializer;
3436

37+
/**
38+
* @var Filesystem
39+
*/
40+
private $fileSystem;
41+
3542
/**
3643
* @param \Magento\Backend\Block\Template\Context $context
3744
* @param \Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages
3845
* @param \Magento\Framework\Registry $registry
3946
* @param array $data
47+
* @param Filesystem $fileSystem
4048
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
4149
* @throws \RuntimeException
4250
*/
4351
public function __construct(
4452
\Magento\Backend\Block\Template\Context $context,
4553
\Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages,
4654
\Magento\Framework\Registry $registry,
55+
Filesystem $fileSystem,
4756
array $data = [],
4857
\Magento\Framework\Serialize\Serializer\Json $serializer = null
4958
) {
5059
$this->_coreRegistry = $registry;
5160
$this->_cmsWysiwygImages = $cmsWysiwygImages;
5261
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
5362
->get(\Magento\Framework\Serialize\Serializer\Json::class);
63+
$this->fileSystem = $fileSystem;
5464
parent::__construct($context, $data);
5565
}
5666

@@ -76,7 +86,7 @@ public function getTreeJson()
7686
'path' => substr($item->getFilename(), strlen($storageRoot)),
7787
'cls' => 'folder',
7888
];
79-
$nestedDirectories = $this->getMediaDirectory()->readRecursively($item->getFilename());
89+
$nestedDirectories = $this->getFilteredNestedDirectories($storageRoot, $item->getFilename());
8090
$hasNestedDirectories = count($nestedDirectories) > 0;
8191

8292
// if no nested directories inside dir, add 'leaf' state so that jstree hides dropdown arrow next to dir
@@ -89,6 +99,27 @@ public function getTreeJson()
8999
return $this->serializer->serialize($jsonArray);
90100
}
91101

102+
/**
103+
* Get nested directories without files
104+
*
105+
* @param string $storageRoot
106+
* @param string $fileName
107+
* @return array
108+
*/
109+
private function getFilteredNestedDirectories(string $storageRoot, string $fileName): array
110+
{
111+
$result = [];
112+
$pathList = $this->getMediaDirectory()->read($fileName);
113+
foreach ($pathList as $directoryPath) {
114+
$directory = $this->fileSystem->getDirectoryReadByPath($storageRoot . $directoryPath);
115+
if (!$directory->isDirectory()) {
116+
continue;
117+
}
118+
$result[] = $directoryPath;
119+
}
120+
return $result;
121+
}
122+
92123
/**
93124
* Json source URL
94125
*

0 commit comments

Comments
 (0)