This repository has been archived by the owner on Apr 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/2.3-develop' into complexity-lim…
…iter
- Loading branch information
Showing
227 changed files
with
6,896 additions
and
1,985 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
app/code/Magento/Backend/Block/Widget/Form/Element/ElementCreator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Backend\Block\Widget\Form\Element; | ||
|
||
use Magento\Eav\Model\Entity\Attribute; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Magento\Framework\Data\Form\Element\Fieldset; | ||
|
||
/** | ||
* Class ElementCreator | ||
* | ||
* @deprecated 100.3.0 in favour of UI component implementation | ||
* @package Magento\Backend\Block\Widget\Form\Element | ||
*/ | ||
class ElementCreator | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $modifiers; | ||
|
||
/** | ||
* ElementCreator constructor. | ||
* | ||
* @param array $modifiers | ||
*/ | ||
public function __construct(array $modifiers = []) | ||
{ | ||
$this->modifiers = $modifiers; | ||
} | ||
|
||
/** | ||
* Creates element | ||
* | ||
* @param Fieldset $fieldset | ||
* @param Attribute $attribute | ||
* | ||
* @return AbstractElement | ||
*/ | ||
public function create(Fieldset $fieldset, Attribute $attribute): AbstractElement | ||
{ | ||
$config = $this->getElementConfig($attribute); | ||
|
||
if (!empty($config['rendererClass'])) { | ||
$fieldType = $config['inputType'] . '_' . $attribute->getAttributeCode(); | ||
$fieldset->addType($fieldType, $config['rendererClass']); | ||
} | ||
|
||
return $fieldset | ||
->addField($config['attribute_code'], $config['inputType'], $config) | ||
->setEntityAttribute($attribute); | ||
} | ||
|
||
/** | ||
* Returns element config | ||
* | ||
* @param Attribute $attribute | ||
* @return array | ||
*/ | ||
private function getElementConfig(Attribute $attribute): array | ||
{ | ||
$defaultConfig = $this->createDefaultConfig($attribute); | ||
$config = $this->modifyConfig($defaultConfig); | ||
|
||
$config['label'] = __($config['label']); | ||
|
||
return $config; | ||
} | ||
|
||
/** | ||
* Returns default config | ||
* | ||
* @param Attribute $attribute | ||
* @return array | ||
*/ | ||
private function createDefaultConfig(Attribute $attribute): array | ||
{ | ||
return [ | ||
'inputType' => $attribute->getFrontend()->getInputType(), | ||
'rendererClass' => $attribute->getFrontend()->getInputRendererClass(), | ||
'attribute_code' => $attribute->getAttributeCode(), | ||
'name' => $attribute->getAttributeCode(), | ||
'label' => $attribute->getFrontend()->getLabel(), | ||
'class' => $attribute->getFrontend()->getClass(), | ||
'required' => $attribute->getIsRequired(), | ||
'note' => $attribute->getNote(), | ||
]; | ||
} | ||
|
||
/** | ||
* Modify config | ||
* | ||
* @param array $config | ||
* @return array | ||
*/ | ||
private function modifyConfig(array $config): array | ||
{ | ||
if ($this->isModified($config['attribute_code'])) { | ||
return $this->applyModifier($config); | ||
} | ||
return $config; | ||
} | ||
|
||
/** | ||
* Returns bool if attribute need to modify | ||
* | ||
* @param string $attribute_code | ||
* @return bool | ||
*/ | ||
private function isModified($attribute_code): bool | ||
{ | ||
return isset($this->modifiers[$attribute_code]); | ||
} | ||
|
||
/** | ||
* Apply modifier to config | ||
* | ||
* @param array $config | ||
* @return array | ||
*/ | ||
private function applyModifier(array $config): array | ||
{ | ||
$modifiedConfig = $this->modifiers[$config['attribute_code']]; | ||
foreach (array_keys($config) as $key) { | ||
if (isset($modifiedConfig[$key])) { | ||
$config[$key] = $modifiedConfig[$key]; | ||
} | ||
} | ||
return $config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
app/code/Magento/Bundle/Test/Mftf/ActionGroup/AdminCreateApiBundleProductActionGroup.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
|
||
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> | ||
<actionGroup name="AdminCreateApiDynamicBundleProductActionGroup"> | ||
<arguments> | ||
<argument name="productName" defaultValue="Api Dynamic Bundle Product" type="string"/> | ||
</arguments> | ||
<!--Create 4 simple products--> | ||
<createData entity="SimpleProduct2" stepKey="simpleProduct1"> | ||
<field key="price">4.99</field> | ||
</createData> | ||
<createData entity="SimpleProduct2" stepKey="simpleProduct2"> | ||
<field key="price">2.89</field> | ||
</createData> | ||
<createData entity="SimpleProduct2" stepKey="simpleProduct3"> | ||
<field key="price">7.33</field> | ||
</createData> | ||
<createData entity="SimpleProduct2" stepKey="simpleProduct4"> | ||
<field key="price">18.25</field> | ||
</createData> | ||
<!-- Create the bundle product based --> | ||
<createData entity="ApiBundleProduct" stepKey="createBundleProduct"> | ||
<field key="name">{{productName}}</field> | ||
</createData> | ||
<createData entity="MultipleSelectOption" stepKey="createBundleOption1_1"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
<field key="required">false</field> | ||
</createData> | ||
<createData entity="CheckboxOption" stepKey="createBundleOption1_2"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
</createData> | ||
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
<requiredEntity createDataKey="createBundleOption1_1"/> | ||
<requiredEntity createDataKey="simpleProduct1"/> | ||
</createData> | ||
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct2"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
<requiredEntity createDataKey="createBundleOption1_1"/> | ||
<requiredEntity createDataKey="simpleProduct2"/> | ||
</createData> | ||
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct3"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
<requiredEntity createDataKey="createBundleOption1_2"/> | ||
<requiredEntity createDataKey="simpleProduct3"/> | ||
</createData> | ||
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct4"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
<requiredEntity createDataKey="createBundleOption1_2"/> | ||
<requiredEntity createDataKey="simpleProduct4"/> | ||
</createData> | ||
</actionGroup> | ||
<actionGroup name="AdminCreateApiFixedBundleProductActionGroup"> | ||
<arguments> | ||
<argument name="productName" defaultValue="Api Fixed Bundle Product" type="string"/> | ||
</arguments> | ||
<!--Create 4 simple products--> | ||
<createData entity="SimpleProduct2" stepKey="simpleProduct1"> | ||
<field key="price">4.99</field> | ||
</createData> | ||
<createData entity="SimpleProduct2" stepKey="simpleProduct2"> | ||
<field key="price">2.89</field> | ||
</createData> | ||
<createData entity="SimpleProduct2" stepKey="simpleProduct3"> | ||
<field key="price">7.33</field> | ||
</createData> | ||
<createData entity="SimpleProduct2" stepKey="simpleProduct4"> | ||
<field key="price">18.25</field> | ||
</createData> | ||
<!-- Create the bundle product based --> | ||
<createData entity="ApiFixedBundleProduct" stepKey="createBundleProduct"> | ||
<field key="name">{{productName}}</field> | ||
</createData> | ||
<createData entity="MultipleSelectOption" stepKey="createBundleOption1_1"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
<field key="required">false</field> | ||
</createData> | ||
<createData entity="CheckboxOption" stepKey="createBundleOption1_2"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
</createData> | ||
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
<requiredEntity createDataKey="createBundleOption1_1"/> | ||
<requiredEntity createDataKey="simpleProduct1"/> | ||
</createData> | ||
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct2"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
<requiredEntity createDataKey="createBundleOption1_1"/> | ||
<requiredEntity createDataKey="simpleProduct2"/> | ||
</createData> | ||
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct3"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
<requiredEntity createDataKey="createBundleOption1_2"/> | ||
<requiredEntity createDataKey="simpleProduct3"/> | ||
</createData> | ||
<createData entity="ApiBundleLink" stepKey="linkOptionToProduct4"> | ||
<requiredEntity createDataKey="createBundleProduct"/> | ||
<requiredEntity createDataKey="createBundleOption1_2"/> | ||
<requiredEntity createDataKey="simpleProduct4"/> | ||
</createData> | ||
</actionGroup> | ||
</actionGroups> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.