Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UsedDefault.php
Go to the documentation of this file.
1 <?php
7 
13 
15 {
19  protected $locator;
20 
24  protected $arrayManager;
25 
29  protected $scopeConfig;
30 
34  protected $meta = [];
35 
41  public function __construct(
45  ) {
46  $this->locator = $locator;
47  $this->scopeConfig = $scopeConfig;
48  $this->arrayManager = $arrayManager;
49  }
50 
54  public function modifyData(array $data)
55  {
56  return $data;
57  }
58 
62  public function modifyMeta(array $meta)
63  {
64  $this->meta = $meta;
65 
66  $this->titleUsedDefault('links_title')
67  ->titleUsedDefault('samples_title')
68  ->priceUsedDefault()
69  ->titleUsedDefaultInGrid('link_title')
70  ->titleUsedDefaultInGrid('sample_title');
71 
72  return $this->meta;
73  }
74 
81  protected function titleUsedDefault($titleIndex)
82  {
83  $canDisplayService = $this->locator->getProduct()->getStoreId();
84  $usedDefault = $this->locator->getProduct()->getAttributeDefaultValue($titleIndex) === false;
85  if ($canDisplayService) {
86  $useDefaultConfig = [
87  'usedDefault' => $usedDefault,
88  'disabled' => $usedDefault,
89  'service' => [
90  'template' => 'ui/form/element/helper/service',
91  ]
92  ];
93  $linksTitlePath = $this->arrayManager->findPath($titleIndex, $this->meta, null, 'children')
94  . static::META_CONFIG_PATH;
95  $this->meta = $this->arrayManager->merge($linksTitlePath, $this->meta, $useDefaultConfig);
96  }
97 
98  return $this;
99  }
100 
106  protected function priceUsedDefault()
107  {
108  $scope = (int)$this->scopeConfig->getValue(
109  \Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE,
110  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
111  );
112  if ($scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE && $this->locator->getProduct()->getStoreId()) {
113  $linkPricePath = $this->arrayManager->findPath('container_link_price', $this->meta, null, 'children');
114  $checkboxPath = $linkPricePath . '/children/use_default_price/arguments/data/config';
115  $useDefaultConfig = [
116  'componentType' => Form\Element\Checkbox::NAME,
117  'formElement' => Form\Field::NAME,
118  'component' => 'Magento_Downloadable/js/components/use-price-default-handler',
119  'description' => __('Use Default Value'),
120  'dataScope' => 'use_default_price',
121  'valueMap' => [
122  'false' => '0',
123  'true' => '1',
124  ],
125  'imports' => [
126  'linksPurchasedSeparately' => '${$.provider}:data.product.links_purchased_separately',
127  ],
128  ];
129  $this->meta = $this->arrayManager->set($checkboxPath, $this->meta, $useDefaultConfig);
130  }
131 
132  return $this;
133  }
134 
141  protected function titleUsedDefaultInGrid($indexTitle)
142  {
143  if ($this->locator->getProduct()->getStoreId()) {
144  $linkTitleGroupPath = $this->arrayManager->findPath(
145  'container_' . $indexTitle,
146  $this->meta,
147  null,
148  'children'
149  );
150  $checkboxPath = $linkTitleGroupPath . '/children/use_default_title/arguments/data/config';
151  $useDefaultConfig = [
152  'componentType' => Form\Element\Checkbox::NAME,
153  'formElement' => Form\Field::NAME,
154  'description' => __('Use Default Value'),
155  'dataScope' => 'use_default_title',
156  'valueMap' => [
157  'false' => '0',
158  'true' => '1',
159  ],
160  'exports' => [
161  'checked' => '${$.parentName}.' . $indexTitle . ':disabled',
162  ],
163  ];
164  $this->meta = $this->arrayManager->set($checkboxPath, $this->meta, $useDefaultConfig);
165  }
166 
167  return $this;
168  }
169 }
__()
Definition: __.php:13
__construct(LocatorInterface $locator, ScopeConfigInterface $scopeConfig, ArrayManager $arrayManager)
Definition: UsedDefault.php:41