Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataLoader.php
Go to the documentation of this file.
1 <?php
7 
11 
13 {
17  protected $request;
18 
23 
27  protected $dataPersistor;
28 
34  public function __construct(
38  ) {
39  $this->request = $request;
40  $this->designConfigRepository = $designConfigRepository;
41  $this->dataPersistor = $dataPersistor;
42  }
43 
49  public function getData()
50  {
51  $scope = $this->request->getParam('scope');
52  $scopeId = $this->request->getParam('scope_id');
53 
54  $data = $this->loadData($scope, $scopeId);
55 
56  $data[$scope]['scope'] = $scope;
57  $data[$scope]['scope_id'] = $scopeId;
58 
59  return $data;
60  }
61 
69  protected function loadData($scope, $scopeId)
70  {
71  $designConfig = $this->designConfigRepository->getByScope($scope, $scopeId);
72  $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData();
73  $data = [];
74  foreach ($fieldsData as $fieldData) {
75  $data[$scope][$fieldData->getFieldConfig()['field']] = $fieldData->getValue();
76  }
77 
78  $storedData = $this->dataPersistor->get('theme_design_config');
79  if (isset($storedData['scope']) && isset($storedData['scope_id'])
80  && $storedData['scope'] == $scope && $storedData['scope_id'] == $scopeId
81  ) {
82  $data[$scope] = $storedData;
83  $this->dataPersistor->clear('theme_design_config');
84  }
85 
86  return $data;
87  }
88 }
__construct(RequestInterface $request, DesignConfigRepositoryInterface $designConfigRepository, DataPersistorInterface $dataPersistor)
Definition: DataLoader.php:34