Skip to main content
2 of 2
added 56 characters in body
Msquare
  • 9.3k
  • 7
  • 27
  • 68

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.

Msquare
  • 9.3k
  • 7
  • 27
  • 68