コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Load data
  *
  * @param string $scope
  * @param string $scopeId
  * @return array
  */
 protected function loadData($scope, $scopeId)
 {
     $designConfig = $this->designConfigRepository->getByScope($scope, $scopeId);
     $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData();
     $data = [];
     foreach ($fieldsData as $fieldData) {
         $data[$scope][$fieldData->getFieldConfig()['field']] = $fieldData->getValue();
     }
     $storedData = $this->dataPersistor->get('theme_design_config');
     if (isset($storedData['scope']) && isset($storedData['scope_id']) && $storedData['scope'] == $scope && $storedData['scope_id'] == $scopeId) {
         $data[$scope] = $storedData;
     }
     return $data;
 }
コード例 #3
0
 /**
  * @param string $scope
  * @param string $scopeId
  * @param string $showFallbackReset
  * @dataProvider dataProviderGetData
  */
 public function testGetData($scope, $scopeId, $showFallbackReset)
 {
     $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $this->scopeFallbackResolver->expects($this->atLeastOnce())->method('getFallbackScope')->with($scope, $scopeId)->willReturn([$scope, $scopeId]);
     $this->storeManager->expects($this->once())->method('isSingleStoreMode')->willReturn(false);
     $this->designConfigRepository->expects($this->once())->method('getByScope')->with($scope, $scopeId)->willReturn($this->designConfig);
     $this->designConfig->expects($this->once())->method('getExtensionAttributes')->willReturn($this->designConfigExtension);
     $this->designConfigExtension->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]);
     $this->designConfigData->expects($this->atLeastOnce())->method('getFieldConfig')->willReturn(['field' => 'field', 'fieldset' => 'fieldset1']);
     $this->designConfigData->expects($this->once())->method('getValue')->willReturn('value');
     $result = $this->model->getData();
     $expected = ['fieldset1' => ['children' => ['field' => ['arguments' => ['data' => ['config' => ['default' => 'value', 'showFallbackReset' => $showFallbackReset]]]]]]];
     $this->assertEquals($expected, $result);
 }
コード例 #4
0
 public function testGetDataWithNoItems()
 {
     $scope = 'websites';
     $scopeId = 1;
     $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $this->designConfigRepository->expects($this->once())->method('getByScope')->with($scope, $scopeId)->willReturn($this->designConfig);
     $this->designConfig->expects($this->once())->method('getExtensionAttributes')->willReturn($this->designConfigExtension);
     $this->designConfigExtension->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]);
     $this->designConfigData->expects($this->once())->method('getFieldConfig')->willReturn(['field' => 'field']);
     $this->designConfigData->expects($this->once())->method('getValue')->willReturn('value');
     $this->dataPersistor->expects($this->once())->method('get')->with('theme_design_config')->willReturn(['scope' => $scope, 'scope_id' => $scopeId]);
     $result = $this->model->getData();
     $this->assertTrue(is_array($result));
     $this->assertTrue(array_key_exists($scope, $result));
     $this->assertTrue(is_array($result[$scope]));
     $this->assertTrue(array_key_exists('scope', $result[$scope]));
     $this->assertTrue(array_key_exists('scope_id', $result[$scope]));
     $this->assertEquals($scope, $result[$scope]['scope']);
     $this->assertEquals($scopeId, $result[$scope]['scope_id']);
 }