0

This is my ui component:

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <listingToolbar name="listing_top">
        <massaction name="listing_massaction">
            <action name="create_barcode">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="type" xsi:type="string">create_barcode</item>
                        <item name="label" xsi:type="string" translate="true">Create Barcode(s)</item>
<!--                        <item name="url" xsi:type="url" path="vendor_product_barcode/product/massCreateBarcode"/>-->
                    </item>
                </argument>
                <argument name="actions" xsi:type="configurableObject">
                    <argument name="class" xsi:type="string">Vendor\ProductBarcode\Ui\Component\Catalog\Product\MassAction\Barcode</argument>
                    <argument name="data" xsi:type="array">
                        <item name="urlPath" xsi:type="string">vendor_product_barcode/product/massCreateBarcode</item>
                        <item name="paramName" xsi:type="string">no_of_printing</item>
                    </argument>
                </argument>
            </action>
        </massaction>
    </listingToolbar>
</listing>

and the content of the Barcode class:

use Magento\Framework\UrlInterface;
class Barcode extends  \Magento\Ui\DataProvider\AbstractDataProvider
{

    protected $urlBuilder;

    public function __construct(
        UrlInterface $urlBuilder
    ) {
        $this->urlBuilder = $urlBuilder;
    }

}

My goal is to add an input field text with a button for my Create barcode option item. And the value of that input field must be parsed to a controller. So far I achieved this:

enter image description here

I'm not sure, how can i add inside of that submenu an input type text with a button. So any advice are welcome. Thnx

1 Answer 1

0

record_list.xml

  <container name="listing_top">
    <massaction name="listing_massaction">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="selectProvider" xsi:type="string">record_list.record_list.records_columns.ids</item>
                <item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
                <item name="indexField" xsi:type="string">id</item>
            </item>
        </argument>
        <action name="create_barcode">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">create_barcode</item>
                    <item name="label" xsi:type="string" translate="true">Create Barcode(s)</item>
                </item>
            </argument>
            <settings>
                <type>create_barcode</type>
                <label translate="true">Create Barcode(s)</label>
                <actions class="VendoreName\ModuleName\Ui\Component\MassAction\CreateBarcode"/>
            </settings>
        </action>
    </massaction>
  </container>

add this code in di.xml

app/code/VendoreName/ModuleName/etc

di.xml

<type name="VendoreName\ModuleName\Ui\Component\MassAction\CreateBarcode">
    <arguments>
        <argument name="data" xsi:type="array">
            <item name="urlPath" xsi:type="string">RouteName/ContorllerName/masscreatebarcode</item>
            <item name="paramName" xsi:type="string">no_of_printing</item>
            <item name="confirm" xsi:type="array">
                <item name="title" xsi:type="string" translatable="true">Create Barcode(s)</item>
                <item name="message" xsi:type="string" translatable="true">Are you sure to create selected record barcode?</item>
            </item>
        </argument>
    </arguments>
</type>

app/code/VendoreName/ModuleName/Ui/Component/MassAction

CreateBarcode.php

<?php

namespace VendoreName\ModuleName\Ui\Component\MassAction;

use Magento\Framework\UrlInterface;
use Zend\Stdlib\JsonSerializable;

class CreateBarcode implements JsonSerializable
{

    protected $options;
    protected $data;
    protected $urlBuilder;
    protected $urlPath;
    protected $paramName;
    protected $additionalData = [];

    public function __construct(
        UrlInterface $urlBuilder,
        array $data = []
    ) {
        $this->data = $data;
        $this->urlBuilder = $urlBuilder;
    }
    public function jsonSerialize()
    {
        if ($this->options === null) {
            $options = [
                [
                    "value" => "0",
                    "label" => ('Barcode - 1'),
                ],
                [
                    "value" => "1",
                    "label" => ('Barcode - 2'),
                ],
                [
                    "value" => "2",
                    "label" => ('Barcode - 3'),
                ],
                [
                    "value" => "3",
                    "label" => ('Barcode - 4'),
                ],
            ];
            $this->prepareData();
            foreach ($options as $optionCode) {
                $this->options[$optionCode['value']] = [
                    'type' => 'status_' . $optionCode['value'],
                    'label' => $optionCode['label'],
                ];

                if ($this->urlPath && $this->paramName) {
                    $this->options[$optionCode['value']]['url'] = $this->urlBuilder->getUrl(
                        $this->urlPath,
                        [$this->paramName => $optionCode['value']]
                    );
                }

                $this->options[$optionCode['value']] = array_merge_recursive(
                    $this->options[$optionCode['value']],
                    $this->additionalData
                );
            }
            $this->options = array_values($this->options);
        }
        return $this->options;
    }

    /**
     * Prepare addition data for subactions
     *
     * @return void
     */
    protected function prepareData()
    {
        foreach ($this->data as $key => $value) {
            switch ($key) {
                case 'urlPath':
                    $this->urlPath = $value;
                    break;
                case 'paramName':
                    $this->paramName = $value;
                    break;
                default:
                    $this->additionalData[$key] = $value;
                    break;
            }
        }
    }
}

app/code/VendoreName/ModuleName/Controller/Adminhtml/ControllerName

MassCreateBarcode.php

<?php

namespace VendoreName\ModuleName\Controller\Adminhtml\ControllerName;

use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Ui\Component\MassAction\Filter;

class MassCreateBarcode extends \Magento\Backend\App\Action
{
    protected $filter;

    public function __construct(
        Context $context,
        Filter $filter,
    ) {
        parent::__construct($context);
        $this->filter = $filter;
    }

    public function execute()
    {
        $selectedAppsid = $this->getRequest()->getParams('no_of_printing');
        print_r($selectedAppsid);
        exit();
        /*
                write your logic for create barcode

        */

    }
}

I Hope This Helps You.

6
  • Thnx for helping me out. It works , but this is not what i want to achieve. If you check my image and my description, it says: "inside of that submenu an input type text with a button" . So Instead of those Barcodes options, I would like to have a input type text and a button. So the user will choose the value for no_of_printing. Not sure If I make myself clear, otherwise please let me know and thnx again for your help :) Commented Mar 30, 2020 at 8:03
  • so any idea how to approach this ? with my proposal ? Or even adding prompt widget - js , would be enough Commented Mar 30, 2020 at 8:10
  • i never use this type of widget but my suggestion is you have unique value for each row. so simple you can add these unique to create unique barcode.
    – Msquare
    Commented Mar 30, 2020 at 8:17
  • and you can give option create barcode from your give value like name type id etc.
    – Msquare
    Commented Mar 30, 2020 at 8:18
  • my goal is to create copies :) of a generated barcode. so if I add 10 and select 2 products. I will have 10 copies of each generated barcode . Not sure how can i achieve this with options (dropdowns) Commented Mar 30, 2020 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.