Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigurableAttributeSetHandler.php
Go to the documentation of this file.
1 <?php
7 
13 
18 {
19  const ATTRIBUTE_SET_HANDLER_MODAL = 'configurable_attribute_set_handler_modal';
20 
24  private $urlBuilder;
25 
29  public function __construct(
30  UrlInterface $urlBuilder
31  ) {
32  $this->urlBuilder = $urlBuilder;
33  }
34 
38  public function modifyData(array $data)
39  {
40  return $data;
41  }
42 
46  public function modifyMeta(array $meta)
47  {
48  $meta = array_merge_recursive(
49  $meta,
50  [
51  self::ATTRIBUTE_SET_HANDLER_MODAL => [
52  'arguments' => [
53  'data' => [
54  'config' => [
55  'componentType' => Modal::NAME,
56  'dataScope' => '',
57  'options' => [
58  'title' => __('Choose Affected Attribute Set'),
59  'type' => 'popup',
60  ],
61  ],
62  ],
63  ],
64  'children' => [
65  'affectedAttributeSetError' => $this->getAttributeSetErrorContainer(),
66  'affectedAttributeSetCurrent' => [
67  'arguments' => [
68  'data' => [
69  'config' => [
70  'dataType' => Form\Element\DataType\Text::NAME,
71  'componentType' => Form\Field::NAME,
72  'formElement' => Form\Element\Checkbox::NAME,
73  'prefer' => 'radio',
74  'description' => __('Add configurable attributes to the current Attribute Set'),
75  'dataScope' => 'configurableAffectedAttributeSet',
76  'valueMap' => [
77  'true' => 'current',
78  'false' => '0',
79  ],
80  'value' => 'current',
81  'sortOrder' => 20,
82  ],
83  ],
84  ],
85  ],
86  'affectedAttributeSetNew' => [
87  'arguments' => [
88  'data' => [
89  'config' => [
90  'dataType' => Form\Element\DataType\Text::NAME,
91  'componentType' => Form\Field::NAME,
92  'formElement' => Form\Element\Checkbox::NAME,
93  'prefer' => 'radio',
94  'description' => __(
95  'Add configurable attributes to the new Attribute Set based on current'
96  ),
97  'dataScope' => 'configurableAffectedAttributeSet',
98  'valueMap' => [
99  'true' => 'new',
100  'false' => '0',
101  ],
102  'value' => '0',
103  'sortOrder' => 30,
104  ],
105  ],
106  ],
107  ],
108  'configurableNewAttributeSetName' => $this->getNewAttributeSet(),
109  'affectedAttributeSetExisting' => [
110  'arguments' => [
111  'data' => [
112  'config' => [
113  'dataType' => Form\Element\DataType\Text::NAME,
114  'componentType' => Form\Field::NAME,
115  'formElement' => Form\Element\Checkbox::NAME,
116  'prefer' => 'radio',
117  'description' => __(
118  'Add configurable attributes to the existing Attribute Set'
119  ),
120  'dataScope' => 'configurableAffectedAttributeSet',
121  'valueMap' => [
122  'true' => 'existing',
123  'false' => '0',
124  ],
125  'value' => '0',
126  'sortOrder' => 50,
127  ],
128  ],
129  ],
130  ],
131  'configurableExistingAttributeSetId' => $this->getExistingAttributeSet($meta),
132  'confirmButtonContainer' => $this->getConfirmButton(),
133  ],
134  ],
135  ]
136  );
137 
138  return $meta;
139  }
140 
146  protected function getConfirmButton()
147  {
148  return [
149  'arguments' => [
150  'data' => [
151  'config' => [
152  'formElement' => 'container',
153  'componentType' => 'container',
154  'label' => false,
155  'template' => 'ui/form/components/complex',
156  'sortOrder' => 100,
157  ],
158  ],
159  ],
160  'children' => [
161  'confirm_button' => [
162  'arguments' => [
163  'data' => [
164  'config' => [
165  'formElement' => 'container',
166  'componentType' => 'container',
167  'component' => 'Magento_Ui/js/form/components/button',
168  'actions' => [
169  [
170  'targetName' => 'product_form.product_form.configurableVariations',
171  'actionName' => 'addNewAttributeSetHandler',
172  ],
173  ],
174  'title' => __('Confirm'),
175  'sortOrder' => 10
176  ],
177  ],
178  ],
179  ],
180  ],
181  ];
182  }
183 
189  protected function getNewAttributeSet()
190  {
191  return [
192  'arguments' => [
193  'data' => [
194  'config' => [
195  'dataType' => Form\Element\DataType\Text::NAME,
196  'formElement' => Form\Element\Input::NAME,
197  'componentType' => Form\Field::NAME,
198  'dataScope' => 'configurableNewAttributeSetName',
199  'additionalClasses' => 'new-attribute-set-name',
200  'label' => __('New Attribute Set Name'),
201  'sortOrder' => 40,
202  'validation' => ['required-entry' => true],
203  'imports' => [
204  'visible' => 'ns = ${ $.ns }, index = affectedAttributeSetNew:checked',
205  'disabled' =>
206  '!ns = ${ $.ns }, index = affectedAttributeSetNew:checked',
207  ]
208  ],
209  ],
210  ],
211  ];
212  }
213 
220  protected function getExistingAttributeSet($meta)
221  {
222  $ret = null;
223  if ($name = $this->getGeneralPanelName($meta)) {
224  if (!empty($meta[$name]['children']['attribute_set_id']['arguments']['data']['config']['options'])) {
225  $options = $meta[$name]['children']['attribute_set_id']['arguments']['data']['config']['options'];
226  $ret = [
227  'arguments' => [
228  'data' => [
229  'config' => [
230  'component' => 'Magento_Ui/js/form/element/ui-select',
231  'disableLabel' => true,
232  'filterOptions' => false,
233  'elementTmpl' => 'ui/grid/filters/elements/ui-select',
234  'formElement' => 'select',
235  'componentType' => Form\Field::NAME,
236  'options' => $options,
237  'label' => __('Choose existing Attribute Set'),
238  'dataScope' => 'configurableExistingAttributeSetId',
239  'sortOrder' => 60,
240  'multiple' => false,
241  'imports' => [
242  'value' => 'ns = ${ $.ns }, index = attribute_set_id:value',
243  'visible' => 'ns = ${ $.ns }, index = affectedAttributeSetExisting:checked',
244  'disabled' =>
245  '!ns = ${ $.ns }, index = affectedAttributeSetExisting:checked',
246  ],
247  ],
248  ],
249  ],
250  ];
251  }
252  }
253 
254  return $ret;
255  }
256 
262  protected function getAttributeSetErrorContainer()
263  {
264  return [
265  'arguments' => [
266  'data' => [
267  'config' => [
268  'component' => 'Magento_Ui/js/form/components/html',
269  'componentType' => Container::NAME,
270  'content' => '',
271  'sortOrder' => 10,
272  'visible' => 0,
273  ],
274  ],
275  ],
276  ];
277  }
278 }
__()
Definition: __.php:13
if(!isset($_GET['name'])) $name
Definition: log.php:14