1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Model\Design\Config\DataProvider;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\ScopeFallbackResolverInterface;
use Magento\Theme\Api\DesignConfigRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;
class MetadataLoader
{
/**
* @var RequestInterface
*/
protected $request;
/**
* @var ScopeFallbackResolverInterface
*/
protected $scopeFallbackResolver;
/**
* @var DesignConfigRepositoryInterface
*/
protected $designConfigRepository;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @param RequestInterface $request
* @param ScopeFallbackResolverInterface $scopeFallbackResolver
* @param DesignConfigRepositoryInterface $designConfigRepository
* @param StoreManagerInterface $storeManager
*/
public function __construct(
RequestInterface $request,
ScopeFallbackResolverInterface $scopeFallbackResolver,
DesignConfigRepositoryInterface $designConfigRepository,
StoreManagerInterface $storeManager
) {
$this->request = $request;
$this->scopeFallbackResolver = $scopeFallbackResolver;
$this->designConfigRepository = $designConfigRepository;
$this->storeManager = $storeManager;
}
/**
* Retrieve configuration metadata
*
* @return array
*/
public function getData()
{
$scope = $this->request->getParam('scope');
$scopeId = $this->request->getParam('scope_id');
$data = [];
if ($scope) {
$showFallbackReset = false;
list($fallbackScope, $fallbackScopeId) = $this->scopeFallbackResolver->getFallbackScope($scope, $scopeId);
if ($fallbackScope && !$this->storeManager->isSingleStoreMode()) {
$scope = $fallbackScope;
$scopeId = $fallbackScopeId;
$showFallbackReset = true;
}
$designConfig = $this->designConfigRepository->getByScope($scope, $scopeId);
$fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData();
foreach ($fieldsData as $fieldData) {
$element = &$data;
foreach (explode('/', $fieldData->getFieldConfig()['fieldset']) as $fieldset) {
if (!isset($element[$fieldset]['children'])) {
$element[$fieldset]['children'] = [];
}
$element = &$element[$fieldset]['children'];
}
$fieldName = $fieldData->getFieldConfig()['field'];
$element[$fieldName]['arguments']['data']['config']['default'] = $fieldData->getValue();
$element[$fieldName]['arguments']['data']['config']['showFallbackReset'] = $showFallbackReset;
}
}
return $data;
}
}