Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/2.3-develop' into complexity-lim…
Browse files Browse the repository at this point in the history
…iter
  • Loading branch information
Valeriy Nayda committed Oct 11, 2018
2 parents 0a4e959 + de50d12 commit e47e861
Show file tree
Hide file tree
Showing 227 changed files with 6,896 additions and 1,985 deletions.
47 changes: 20 additions & 27 deletions app/code/Magento/Backend/Block/Widget/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Backend\Block\Widget;

use Magento\Framework\App\ObjectManager;

/**
* Backend form widget
*
Expand All @@ -27,13 +30,23 @@ class Form extends \Magento\Backend\Block\Widget
*/
protected $_template = 'Magento_Backend::widget/form.phtml';

/** @var Form\Element\ElementCreator */
private $creator;

/**
* Constructs form
*
* @param \Magento\Backend\Block\Template\Context $context
* @param array $data
* @param Form\Element\ElementCreator|null $creator
*/
public function __construct(\Magento\Backend\Block\Template\Context $context, array $data = [])
{
public function __construct(
\Magento\Backend\Block\Template\Context $context,
array $data = [],
Form\Element\ElementCreator $creator = null
) {
parent::__construct($context, $data);
$this->creator = $creator ?: ObjectManager::getInstance()->get(Form\Element\ElementCreator::class);
}

/**
Expand Down Expand Up @@ -148,6 +161,7 @@ protected function _beforeToHtml()

/**
* Initialize form fields values
*
* Method will be called after prepareForm and can be used for field values initialization
*
* @return $this
Expand All @@ -173,32 +187,11 @@ protected function _setFieldset($attributes, $fieldset, $exclude = [])
if (!$this->_isAttributeVisible($attribute)) {
continue;
}
if (($inputType = $attribute->getFrontend()->getInputType()) && !in_array(
$attribute->getAttributeCode(),
$exclude
) && ('media_image' != $inputType || $attribute->getAttributeCode() == 'image')
if (($inputType = $attribute->getFrontend()->getInputType())
&& !in_array($attribute->getAttributeCode(), $exclude)
&& ('media_image' !== $inputType || $attribute->getAttributeCode() == 'image')
) {
$fieldType = $inputType;
$rendererClass = $attribute->getFrontend()->getInputRendererClass();
if (!empty($rendererClass)) {
$fieldType = $inputType . '_' . $attribute->getAttributeCode();
$fieldset->addType($fieldType, $rendererClass);
}

$element = $fieldset->addField(
$attribute->getAttributeCode(),
$fieldType,
[
'name' => $attribute->getAttributeCode(),
'label' => $attribute->getFrontend()->getLocalizedLabel(),
'class' => $attribute->getFrontend()->getClass(),
'required' => $attribute->getIsRequired(),
'note' => $attribute->getNote()
]
)->setEntityAttribute(
$attribute
);

$element = $this->creator->create($fieldset, $attribute);
$element->setAfterElementHtml($this->_getAdditionalElementHtml($element));

$this->_applyTypeSpecificConfig($inputType, $element, $attribute);
Expand Down
136 changes: 136 additions & 0 deletions app/code/Magento/Backend/Block/Widget/Form/Element/ElementCreator.php
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<% if (data.items.length) { %>
<% _.each(data.items, function(value){ %>
<li class="item"
<%- data.optionData(value) %>
<%= data.optionData(value) %>
>
<a href="<%- value.url %>" class="title"><%- value.name %></a>
<span class="type"><%- value.type %></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public function getJsonConfig()
$configValue = $preConfiguredValues->getData('bundle_option/' . $optionId);
if ($configValue) {
$defaultValues[$optionId] = $configValue;
$configQty = $preConfiguredValues->getData('bundle_option_qty/' . $optionId);
if ($configQty) {
$options[$optionId]['selections'][$configValue]['qty'] = $configQty;
}
}
}
$position++;
Expand Down
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>
15 changes: 15 additions & 0 deletions app/code/Magento/Bundle/Test/Mftf/Data/ProductData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,19 @@
<requiredEntity type="custom_attribute">CustomAttributeDynamicPrice</requiredEntity>
<requiredEntity type="custom_attribute">CustomAttributePriceViewRange</requiredEntity>
</entity>
<entity name="ApiFixedBundleProduct" type="product2">
<data key="name" unique="suffix">Api Fixed Bundle Product</data>
<data key="sku" unique="suffix">api-fixed-bundle-product</data>
<data key="type_id">bundle</data>
<data key="attribute_set_id">4</data>
<data key="price">1.23</data>
<data key="visibility">4</data>
<data key="status">1</data>
<data key="urlKey" unique="suffix">api-fixed-bundle-product</data>
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
<requiredEntity type="custom_attribute">ApiProductDescription</requiredEntity>
<requiredEntity type="custom_attribute">ApiProductShortDescription</requiredEntity>
<requiredEntity type="custom_attribute">CustomAttributeFixPrice</requiredEntity>
<requiredEntity type="custom_attribute">CustomAttributePriceView</requiredEntity>
</entity>
</entities>
Loading

0 comments on commit e47e861

Please sign in to comment.