Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataProvider.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Theme\Model\ResourceModel\Design\Config\CollectionFactory;
15 
17 {
21  protected $loadedData;
22 
26  protected $collection;
27 
31  protected $dataLoader;
32 
36  private $metadataLoader;
37 
41  private $settingChecker;
42 
46  private $request;
47 
51  private $scopeCodeResolver;
52 
63  public function __construct(
64  $name,
67  DataProvider\DataLoader $dataLoader,
68  DataProvider\MetadataLoader $metadataLoader,
69  CollectionFactory $configCollectionFactory,
70  array $meta = [],
71  array $data = []
72  ) {
73  parent::__construct(
74  $name,
77  $meta,
78  $data
79  );
80  $this->dataLoader = $dataLoader;
81  $this->metadataLoader = $metadataLoader;
82 
83  $this->collection = $configCollectionFactory->create();
84 
85  $this->meta = array_merge($this->meta, $this->metadataLoader->getData());
86  }
87 
91  public function getData()
92  {
93  if (isset($this->loadedData)) {
94  return $this->loadedData;
95  }
96 
97  $this->loadedData = $this->dataLoader->getData();
98  return $this->loadedData;
99  }
100 
104  public function getMeta()
105  {
106  $meta = parent::getMeta();
107  if (!isset($meta['other_settings']['children'])) {
108  return $meta;
109  }
110 
111  $request = $this->getRequest()->getParams();
112  if (!isset($request['scope'])) {
113  return $meta;
114  }
115 
116  $scope = $request['scope'];
117  $scopeCode = $this->getScopeCodeResolver()->resolve(
118  $scope,
119  isset($request['scope_id']) ? $request['scope_id'] : null
120  );
121 
122  foreach ($meta['other_settings']['children'] as $settingGroupName => &$settingGroup) {
123  foreach ($settingGroup['children'] as $fieldName => &$field) {
124  $path = sprintf(
125  'design/%s/%s',
126  $settingGroupName,
127  preg_replace('/^' . $settingGroupName . '_/', '', $fieldName)
128  );
129  $isReadOnly = $this->getSettingChecker()->isReadOnly(
130  $path,
131  $scope,
132  $scopeCode
133  );
134 
135  if ($isReadOnly) {
136  $field['arguments']['data']['config']['disabled'] = true;
137  $field['arguments']['data']['config']['is_disable_inheritance'] = true;
138  }
139  }
140  }
141 
142  if (isset($meta['other_settings']['children']['search_engine_robots']['children'])) {
143  $meta['other_settings']['children']['search_engine_robots']['children'] = array_merge(
144  $meta['other_settings']['children']['search_engine_robots']['children'],
145  $this->getSearchEngineRobotsMetadata(
146  $scope,
147  $meta['other_settings']['children']['search_engine_robots']['children']
148  )
149  );
150  }
151 
152  return $meta;
153  }
154 
164  private function getSearchEngineRobotsMetadata($scope, array $fields = [])
165  {
166  if ($scope == \Magento\Store\Model\ScopeInterface::SCOPE_STORES) {
167  $resetToDefaultsData = [
168  'arguments' => [
169  'data' => [
170  'config' => [
171  'disabled' => true,
172  'is_disable_inheritance' => true,
173  ],
174  ],
175  ],
176  ];
177  $fields = array_merge($fields, ['reset_to_defaults' => $resetToDefaultsData]);
178  foreach ($fields as &$field) {
179  $field['arguments']['data']['config']['disabled'] = true;
180  $field['arguments']['data']['config']['is_disable_inheritance'] = true;
181  }
182  }
183  return $fields;
184  }
185 
190  private function getScopeCodeResolver()
191  {
192  if ($this->scopeCodeResolver === null) {
193  $this->scopeCodeResolver = ObjectManager::getInstance()->get(ScopeCodeResolver::class);
194  }
195  return $this->scopeCodeResolver;
196  }
197 
202  private function getSettingChecker()
203  {
204  if ($this->settingChecker === null) {
205  $this->settingChecker = ObjectManager::getInstance()->get(SettingChecker::class);
206  }
207  return $this->settingChecker;
208  }
209 
214  private function getRequest()
215  {
216  if ($this->request === null) {
217  $this->request = ObjectManager::getInstance()->get(RequestInterface::class);
218  }
219  return $this->request;
220  }
221 }
__construct( $name, $primaryFieldName, $requestFieldName, DataProvider\DataLoader $dataLoader, DataProvider\MetadataLoader $metadataLoader, CollectionFactory $configCollectionFactory, array $meta=[], array $data=[])
$fields
Definition: details.phtml:14