Skip to content

Commit bb29938

Browse files
committed
MC-14937: Complete Page Builder Analytics data collection
- Introduce custom collector to ensure Page Builder configuration is loaded from adminhtml
1 parent a6a9519 commit bb29938

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\PageBuilder\Model\View\File\Collector;
10+
11+
use Magento\Framework\Component\ComponentRegistrar;
12+
use Magento\Framework\Component\DirSearch;
13+
use Magento\Framework\View\Design\ThemeInterface;
14+
use Magento\Framework\View\File\CollectorInterface;
15+
use Magento\Framework\View\File\Factory as FileFactory;
16+
17+
/**
18+
* Source of Page Builder view files introduced by modules
19+
*/
20+
class PageBuilder implements CollectorInterface
21+
{
22+
/**
23+
* @var DirSearch
24+
*/
25+
protected $componentDirSearch;
26+
27+
/**
28+
* @var string
29+
*/
30+
private $subDir;
31+
32+
/**
33+
* @var FileFactory
34+
*/
35+
private $fileFactory;
36+
37+
/**
38+
* Constructor
39+
*
40+
* @param DirSearch $dirSearch
41+
* @param FileFactory $fileFactory
42+
* @param string $subDir
43+
*/
44+
public function __construct(
45+
DirSearch $dirSearch,
46+
FileFactory $fileFactory,
47+
$subDir = ''
48+
) {
49+
$this->componentDirSearch = $dirSearch;
50+
$this->fileFactory = $fileFactory;
51+
$this->subDir = $subDir ? $subDir . '/' : '';
52+
}
53+
54+
/**
55+
* Retrieve files, they're only contained within the adminhtml directory
56+
*
57+
* @param \Magento\Framework\View\Design\ThemeInterface $theme
58+
* @param string $filePath
59+
* @return \Magento\Framework\View\File[]
60+
*/
61+
public function getFiles(ThemeInterface $theme, $filePath)
62+
{
63+
$adminArea = \Magento\Framework\App\Area::AREA_ADMINHTML;
64+
$result = [];
65+
$pageBuilderFiles = $this->componentDirSearch->collectFilesWithContext(
66+
ComponentRegistrar::MODULE,
67+
"view/{$adminArea}/{$this->subDir}{$filePath}"
68+
);
69+
foreach ($pageBuilderFiles as $file) {
70+
$result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName(), null, true);
71+
}
72+
return $result;
73+
}
74+
}

app/code/Magento/PageBuilder/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
</argument>
103103
</arguments>
104104
</type>
105-
<virtualType name="pageBuilderComponentAggregatedSourceBase" type="Magento\Framework\View\File\Collector\Base">
105+
<virtualType name="pageBuilderComponentAggregatedSourceBase" type="Magento\PageBuilder\Model\View\File\Collector\PageBuilder">
106106
<arguments>
107107
<argument name="subDir" xsi:type="string">pagebuilder</argument>
108108
</arguments>

0 commit comments

Comments
 (0)