Created
July 25, 2019 03:49
-
-
Save ProxiBlue/a582073bbf579d41d6c60a89a83b4122 to your computer and use it in GitHub Desktop.
complex m2 ui
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
<?php | |
declare(strict_types=1); | |
namespace Enjo\Pure\Ui\DataProvider\Product\Form\Modifier; | |
use Magento\Ui\Component\Container; | |
use Magento\Ui\Component\DynamicRows; | |
use Magento\Ui\Component\Form\Field; | |
use Magento\Ui\Component\Form\Fieldset; | |
use Magento\Ui\Component\Form\Element\Textarea; | |
use Magento\Ui\Component\Form\Element\Select; | |
use Magento\Ui\Component\Form\Element\DataType\Text; | |
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; | |
class StatusContentAttr extends AbstractModifier | |
{ | |
const ATTRIBUTE_CODE = 'enjopure_status_content'; | |
const ATTRIBUTE_GROUP = 'pure-information'; | |
/** | |
* @var \Magento\Catalog\Model\Locator\LocatorInterface | |
*/ | |
protected $_locator; | |
/** | |
* @var \Magento\Framework\Stdlib\ArrayManager | |
*/ | |
protected $_arrayManager; | |
/** | |
* @var \Magento\Eav\Model\Entity\Attribute | |
*/ | |
protected $_eavEntity; | |
/** | |
* FeaturedInfoList constructor. | |
*/ | |
public function __construct( | |
\Magento\Catalog\Model\Locator\LocatorInterface $locator, | |
\Magento\Framework\Stdlib\ArrayManager $arrayManager, | |
\Magento\Eav\Model\Entity\Attribute $eavEntity | |
) | |
{ | |
$this->_locator = $locator; | |
$this->_arrayManager = $arrayManager; | |
$this->_eavEntity = $eavEntity; | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function modifyData(array $data): array | |
{ | |
return $data; | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function modifyMeta(array $meta): array | |
{ | |
$attributePath = $this->_arrayManager->findPath( | |
static::ATTRIBUTE_CODE, | |
$meta, | |
null, | |
'children' | |
); | |
$scopeLabel = $this->_arrayManager->get($attributePath . '/arguments/data/config/scopeLabel', $meta); | |
$meta[static::ATTRIBUTE_GROUP]['children']['container_enjopure_status_content']['children'] = | |
[static::ATTRIBUTE_CODE => $this->getItemListStructure(10, $scopeLabel)]; | |
return $meta; | |
} | |
/** | |
* @param $sortOrder | |
* @return array | |
*/ | |
protected function getItemListStructure($sortOrder, $scopeLabel): array | |
{ | |
return [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'componentType' => DynamicRows::NAME, | |
'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows', | |
'label' => 'Status Content', | |
'scopeLabel' => $scopeLabel, | |
'addButtonLabel' => __('Add Item'), | |
'sortOrder' => $sortOrder, | |
'additionalClasses' => 'custom-admin-wide-field', | |
'code' => 'enjopure_status_content', | |
'source' => 'pure-information' | |
], | |
], | |
], | |
'children' => [ | |
'record' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'componentType' => Container::NAME, | |
'component' => 'Magento_Ui/js/dynamic-rows/record', | |
'isTemplate' => true, | |
'is_collection' => true, | |
'label' => __('Record Label') | |
], | |
], | |
], | |
'children' => [ | |
'status-container' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'label' => __('Status'), | |
'componentType' => Fieldset::NAME, | |
'dataScope' => static::ATTRIBUTE_CODE, | |
'scopeLabel' => $scopeLabel, | |
], | |
], | |
], | |
'children' => [ | |
'status' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'label' => __('Status'), | |
'componentType' => Field::NAME, | |
'formElement' => Select::NAME, | |
'dataScope' => 'status', | |
'dataType' => Text::NAME, | |
'sortOrder' => 1, | |
'options' => [ | |
['value' => 'unknown', 'label' => __('Unknown')], | |
['value' => 'never', 'label' => __('Never')], | |
['value' => 'expired', 'label' => __('Expired')], | |
['value' => 'active', 'label' => __('Active')] | |
], | |
], | |
], | |
], | |
], | |
'rooms_left' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'label' => __('Rooms Left'), | |
'componentType' => Field::NAME, | |
'formElement' => Select::NAME, | |
'dataScope' => 'rooms_left', | |
'dataType' => Text::NAME, | |
'sortOrder' => 10, | |
'options' => [ | |
['value' => 'any', 'label' => __('Any')], | |
['value' => '1', 'label' => __('1')], | |
['value' => '2', 'label' => __('2')], | |
['value' => '3', 'label' => __('3')], | |
['value' => '4', 'label' => __('4')], | |
['value' => '5', 'label' => __('5')], | |
], | |
], | |
], | |
], | |
], | |
], | |
], | |
'content-container' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'label' => __('Content'), | |
'componentType' => Fieldset::NAME, | |
'dataScope' => static::ATTRIBUTE_CODE, | |
'scopeLabel' => $scopeLabel, | |
], | |
], | |
], | |
'children' => [ | |
'icon_image' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'label' => __('Icon Image'), | |
'componentType' => Field::NAME, | |
'formElement' => Select::NAME, | |
'dataScope' => 'icon_image', | |
'dataType' => Text::NAME, | |
'sortOrder' => 10, | |
'options' => [ | |
['value' => 'house', 'label' => __('House')], | |
['value' => 'kitchen', 'label' => __('Kitchen')], | |
['value' => 'bathroom', 'label' => __('Bathroom')], | |
['value' => 'living', 'label' => __('Living')], | |
['value' => 'floor', 'label' => __('floor')], | |
['value' => 'window', 'label' => __('Window')], | |
['value' => 'outdoor', 'label' => __('Outdoor')], | |
['value' => 'sante', 'label' => __('Sante')], | |
], | |
], | |
], | |
], | |
], | |
'icon_line_colour' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'label' => __('Icon Line Colour'), | |
'componentType' => Field::NAME, | |
'formElement' => Select::NAME, | |
'dataScope' => 'icon_line_colour', | |
'dataType' => Text::NAME, | |
'sortOrder' => 15, | |
'options' => [ | |
['value' => 'grey1', 'label' => __('Gray 1 [#A0A0A0]')], | |
['value' => 'grey6', 'label' => __('Grey 6 [#828284]')], | |
['value' => 'white1', 'label' => __('White 1 [#FFFFFF]')], | |
['value' => 'red1', 'label' => __('Red 1 [#FF584D]')], | |
['value' => 'yellow1', 'label' => __('Yellow 1 [#FFE24D]')], | |
['value' => 'green1', 'label' => __('Green 1 [#C7E9E0]')], | |
['value' => 'green2', 'label' => __('Green 2 [#90D2C1]')], | |
['value' => 'blue1', 'label' => __('Blue 1 [#99CAEA]')], | |
['value' => 'pink1', 'label' => __('Pink 1 [#F5C7B8]')], | |
], | |
], | |
], | |
], | |
], | |
'icon_background_colour' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'label' => __('Icon Background Colour'), | |
'componentType' => Field::NAME, | |
'formElement' => Select::NAME, | |
'dataScope' => 'icon_background_colour', | |
'dataType' => Text::NAME, | |
'sortOrder' => 18, | |
'options' => [ | |
['value' => 'grey1', 'label' => __('Gray 1 [#A0A0A0]')], | |
['value' => 'grey6', 'label' => __('Grey 6 [#828284]')], | |
['value' => 'white1', 'label' => __('White 1 [#FFFFFF]')], | |
['value' => 'red1', 'label' => __('Red 1 [#FF584D]')], | |
['value' => 'yellow1', 'label' => __('Yellow 1 [#FFE24D]')], | |
['value' => 'green1', 'label' => __('Green 1 [#C7E9E0]')], | |
['value' => 'green2', 'label' => __('Green 2 [#90D2C1]')], | |
['value' => 'blue1', 'label' => __('Blue 1 [#99CAEA]')], | |
['value' => 'pink1', 'label' => __('Pink 1 [#F5C7B8]')], | |
], | |
], | |
], | |
], | |
], | |
'content' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'label' => __('Content'), | |
'componentType' => Field::NAME, | |
'formElement' => Textarea::NAME, | |
'dataScope' => 'content', | |
'dataType' => Textarea::NAME, | |
'sortOrder' => 20, | |
], | |
], | |
], | |
], | |
], | |
], | |
'delete-container' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'label' => __('Delete'), | |
'componentType' => Fieldset::NAME, | |
'dataScope' => static::ATTRIBUTE_CODE, | |
'scopeLabel' => $scopeLabel, | |
], | |
], | |
], | |
'children' => [ | |
'status' => [ | |
'arguments' => [ | |
'data' => [ | |
'config' => [ | |
'componentType' => 'actionDelete', | |
'dataType' => Text::NAME, | |
'label' => '', | |
'sortOrder' => 40, | |
], | |
], | |
], | |
], | |
], | |
], | |
], | |
], | |
], | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment