Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Dotancohen\Foo\Ui\DataProvider\Product\Form\Modifier;
- use Magento\Catalog\Model\Locator\LocatorInterface;
- use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
- class Features extends AbstractModifier {
- protected $_product;
- /**
- * @param LocatorInterface $locator
- */
- public function __construct(LocatorInterface $locator)
- {
- $this->_product = $locator->getProduct();
- }
- public function modifyData(array $data) : array
- {
- $product_id = $this->_product->getId();
- $data[$product_id]['product']['foo-and-bar-features'] = array (
- 0 => array (
- 'option_id' => '66',
- 'product_id' => $product_id,
- 'type' => 'radio',
- 'is_require' => '0',
- 'sort_order' => '1',
- 'title' => 'Bars',
- 'display_name' => 'Bars',
- 'values' => array (
- 0 => array (
- 'option_id' => $product_id,
- 'sort_order' => '2',
- 'title' => 'A5',
- 'display_name' => 'A5',
- 'price' => '2.000000',
- 'enabled' => '1',
- ),
- 1 => array (
- 'option_id' => $product_id,
- 'sort_order' => '3',
- 'title' => 'A4',
- 'display_name' => 'A4',
- 'price' => '4.000000',
- 'enabled' => '0',
- ),
- ),
- ),
- 1 => array (
- 'option_id' => '67',
- 'product_id' => $product_id,
- 'type' => 'radio',
- 'is_require' => '0',
- 'sort_order' => '2',
- 'title' => 'Foos',
- 'display_name' => 'Foos',
- 'values' => array (
- 0 => array (
- 'option_id' => '67',
- 'sort_order' => '1',
- 'title' => 'Square',
- 'display_name' => 'Square',
- 'price' => '0.000000',
- 'enabled' => '0',
- ),
- 1 => array (
- 'option_id' => '67',
- 'sort_order' => '2',
- 'title' => 'Landscape',
- 'display_name' => 'Landscape',
- 'price' => '0.000000',
- 'enabled' => '1',
- ),
- 2 => array (
- 'option_id' => '67',
- 'sort_order' => '3',
- 'title' => 'Portrait',
- 'display_name' => 'Portrait',
- 'price' => '0.000000',
- 'enabled' => '1',
- ),
- ),
- ),
- );
- return $data;
- }
- public function modifyMeta(array $meta) : array
- {
- if ( !$this->_product ) {
- return $meta;
- }
- $product_id = $this->_product->getId();
- $meta['exclude_modal'] = array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'componentType' => 'modal',
- 'dataScope' => '',
- 'provider' => 'product_form.product_form_data_source',
- 'ns' => 'product_form',
- 'options' => array (
- 'title' => 'Configure Particular Foo or Bar', /* How to Display the Foo ID or Bar ID here? */
- 'buttons' => array (
- 0 => array (
- 'text' => 'Save',
- 'class' => 'action-primary',
- 'actions' => array (
- 0 => array (
- 'targetName' => 'index = product_form',
- 'actionName' => 'save',
- ),
- 1 => 'closeModal',
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- 'children' => array (
- 'modal_content' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'autoRender' => false,
- 'componentType' => 'container',
- 'dataScope' => 'data.product',
- 'externalProvider' => 'data.product_data_source',
- 'ns' => 'product_form',
- 'render_url' => 'https://example.com/admin/mui/index/render/key/123abc/',
- 'realTimeLink' => true,
- 'behaviourType' => 'edit',
- 'externalFilterMode' => true,
- 'currentProductId' => $product_id,
- ),
- ),
- ),
- 'children' => array (
- 'modal-fieldset' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'label' => 'Fieldset',
- 'componentType' => 'fieldset',
- 'dataScope' => 'foos_features',
- 'collapsible' => true,
- 'sortOrder' => 10,
- 'opened' => true,
- ),
- ),
- ),
- 'children' => array (
- /* These "Features" will be different for each Foo and Bar! How to get the Foo or Bar ID to invoke a method which will return the proper data? */
- 'first_feature' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'label' => 'Feature the first',
- 'dataScope' => 'first_feature',
- 'componentType' => 'field',
- 'dataType' => 'text',
- 'formElement' => 'checkbox',
- 'valueMap' => array (
- 'true' => 1,
- 'false' => 0,
- ),
- 'sortOrder' => 10,
- ),
- ),
- ),
- ),
- 'second_feature' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'label' => 'Feature the second',
- 'dataScope' => 'second_feature',
- 'componentType' => 'field',
- 'dataType' => 'text',
- 'formElement' => 'checkbox',
- 'valueMap' => array (
- 'true' => '1',
- 'false' => '0',
- ),
- 'sortOrder' => 20,
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- );
- /* */
- $meta['foos_and_bars'] = array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'label' => 'Foos and Bars',
- 'dataScope' => 'data.product',
- 'componentType' => 'fieldset',
- 'collapsible' => true,
- 'opened' => true,
- 'sortOrder' => 10,
- ),
- ),
- ),
- 'children' => array (
- 'foo-and-bar-features' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'remove' => 'remove',
- 'addButtonLabel' => 'Add Option',
- 'componentType' => 'dynamicRows',
- 'component' => 'Magento_Catalog/js/components/dynamic-rows-import-custom-options',
- 'template' => 'ui/dynamic-rows/templates/collapsible',
- 'additionalClasses' => 'admin__field-wide',
- 'deleteProperty' => 'is_delete',
- 'deleteValue' => '1',
- 'addButton' => false,
- 'renderDefaultRecord' => false,
- 'columnsHeader' => false,
- 'collapsibleHeader' => true,
- 'sortOrder' => 30,
- 'dataProvider' => 'foo_product_custom_options_listing',
- 'imports' => array (
- 'insertData' => '${ $.provider }:${ $.dataProvider }',
- '__disableTmpl' => array (
- 'insertData' => false,
- ),
- ),
- ),
- ),
- ),
- 'children' => array (
- 'record' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'headerLabel' => 'New Option',
- 'componentType' => 'container',
- 'component' => 'Magento_Ui/js/dynamic-rows/record',
- 'positionProvider' => 'container_option.sort_order',
- 'isTemplate' => true,
- 'is_collection' => true,
- ),
- ),
- ),
- 'children' => array (
- 'container_option' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'label' => NULL,
- 'componentType' => 'fieldset',
- 'collapsible' => true,
- 'sortOrder' => 10,
- 'opened' => true,
- ),
- ),
- ),
- 'children' => array (
- 'sort_order' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'dataScope' => 'sort_order',
- 'componentType' => 'field',
- 'dataType' => 'number',
- 'formElement' => 'hidden',
- 'visible' => false,
- 'sortOrder' => 40,
- ),
- ),
- ),
- ),
- 'container_common' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'componentType' => 'container',
- 'formElement' => 'container',
- 'component' => 'Magento_Ui/js/form/components/group',
- 'breakLine' => false,
- 'showLabel' => false,
- 'additionalClasses' => 'admin__field-group-columns admin__control-group-equal',
- 'sortOrder' => 10,
- ),
- ),
- ),
- 'children' => array (
- 'option_id' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'dataScope' => 'option_id',
- 'componentType' => 'field',
- 'formElement' => 'input',
- 'sortOrder' => 10,
- 'visible' => false,
- ),
- ),
- ),
- ),
- 'display_name' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'label' => 'Display Name',
- 'dataScope' => 'display_name',
- 'componentType' => 'field',
- 'dataType' => 'text',
- 'formElement' => 'input',
- 'sortOrder' => 20,
- 'validation' => array (
- 'required-entry' => false,
- ),
- 'component' => 'Magento_Catalog/component/static-type-input',
- 'valueUpdate' => 'input',
- 'imports' => array (
- 'optionId' => '${ $.provider }:${ $.parentScope }.option_id',
- 'isUseDefault' => '${ $.provider }:${ $.parentScope }.is_use_default',
- '__disableTmpl' => array (
- 'optionId' => false,
- 'isUseDefault' => false,
- ),
- ),
- ),
- ),
- ),
- ),
- 'type' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'label' => 'Display Location',
- 'dataScope' => 'display_location',
- 'componentType' => 'field',
- 'dataType' => 'text',
- 'formElement' => 'select',
- 'component' => 'Magento_Catalog/js/custom-options-type',
- 'elementTmpl' => 'ui/grid/filters/elements/ui-select',
- 'options' => array (
- 0 => array (
- 'label' => 'Before Editor',
- 'value' => 'before_editor',
- ),
- 1 => array (
- 'label' => 'After Editor',
- 'value' => 'after_editor',
- ),
- ),
- 'disableLabel' => true,
- 'multiple' => false,
- 'selectedPlaceholders' => array (
- 'defaultPlaceholder' => '-- Please select --',
- ),
- 'validation' => array (
- 'required-entry' => false,
- ),
- 'values' => array (
- 0 => 'before_editor',
- 1 => 'after_editor',
- ),
- 'indexes' => array (
- 0 => 'container_type_static',
- ),
- 'sortOrder' => 30,
- ),
- ),
- ),
- ),
- ),
- ),
- 'values' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'componentType' => 'dynamicRows',
- 'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows',
- 'additionalClasses' => 'admin__field-wide',
- 'renderDefaultRecord' => false,
- 'sortOrder' => 30,
- ),
- ),
- ),
- 'children' => array (
- 'record' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'componentType' => 'container',
- 'component' => 'Magento_Ui/js/dynamic-rows/record',
- 'positionProvider' => 'sort_order',
- 'isTemplate' => true,
- 'is_collection' => true,
- ),
- ),
- ),
- 'children' => array (
- 'enabled' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'label' => 'Enabled',
- 'dataScope' => 'enabled',
- 'componentType' => 'field',
- 'dataType' => 'text',
- 'formElement' => 'checkbox',
- 'sortOrder' => 5,
- 'valueMap' => array (
- 'true' => '1',
- 'false' => '0',
- ),
- ),
- ),
- ),
- ),
- 'display_name' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'label' => 'Display Name',
- 'dataScope' => 'display_name',
- 'componentType' => 'field',
- 'dataType' => 'text',
- 'formElement' => 'input',
- 'sortOrder' => 10,
- 'validation' => array (
- 'required-entry' => false,
- ),
- ),
- ),
- ),
- ),
- 'price' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'label' => 'Price',
- 'dataScope' => 'price',
- 'componentType' => 'field',
- 'dataType' => 'number',
- 'formElement' => 'input',
- 'component' => 'Magento_Catalog/js/components/custom-options-component',
- 'addbefore' => '$',
- 'template' => 'Magento_Catalog/form/field',
- 'sortOrder' => 20,
- 'validation' => array (
- 'validate-number' => true,
- ),
- ),
- ),
- ),
- ),
- 'sort_order' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'dataScope' => 'sort_order',
- 'componentType' => 'field',
- 'dataType' => 'number',
- 'formElement' => 'hidden',
- 'visible' => false,
- 'sortOrder' => 50,
- ),
- ),
- ),
- ),
- 'cofigure_modal' => array (
- 'arguments' => array (
- 'data' => array (
- 'config' => array (
- 'title' => 'Configure Foo',
- 'formElement' => 'container',
- 'componentType' => 'container',
- 'component' => 'Magento_Ui/js/form/components/button',
- 'actions' => [
- [
- 'targetName' => 'ns=product_form, index=exclude_modal',
- 'actionName' => 'openModal',
- ],
- ],
- 'sortOrder' => 80,
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- );
- return $meta;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement