How select button is visible on the Magento admin side?

In the XML file, we need to add the following code.

example in which file this should be added,
Homepage->ImageUpload->view->adminhtml->ui_component->homepage_imageupload_image_listing.xml

<actionsColumn name="actions" class="HomePage\ImageUpload\Ui\Component\Listing\Column\BannerActions">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="indexField" xsi:type="string">id</item>
                </item>
            </argument>
        </actionsColumn>

And in BannerActions.php

<?php
namespace HomePage\ImageUpload\Ui\Component\Listing\Column;

use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Escaper;

/**
 * Class BannerActions
 */
class BannerActions extends Column
{
    /**
     * Url path
     */
    const URL_PATH_EDIT = 'homepage_imageupload/image/edit';
    const URL_PATH_DELETE = 'homepage_imageupload/image/delete';

    /**
     * @var UrlInterface
     */
    protected $urlBuilder;

    /**
     * Escaper.
     *
     * @var Escaper
     */
    private $escaper;

    /**
     * Constructor
     *
     * @param ContextInterface $context
     * @param UiComponentFactory $uiComponentFactory
     * @param UrlInterface $urlBuilder
     * @param array $components
     * @param array $data
     */
    public function __construct(
        ContextInterface $context,
        UiComponentFactory $uiComponentFactory,
        UrlInterface $urlBuilder,
        array $components = [],
        array $data = []
    ) {
        $this->urlBuilder = $urlBuilder;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }

    /**
     * Prepare Data Source.
     *
     * @param array $dataSource
     * @return array
     */
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
                    foreach ($dataSource['data']['items'] as & $item) {
                        if (isset($item['id'])) {
                            $name = $this->getEscaper()->escapeHtml($item['first_name']);
                            $item[$this->getData('name')] = [
                                'edit' => [
                                    'href' => $this->urlBuilder->getUrl(
                                        static::URL_PATH_EDIT,
                                        [
                                            'id' => $item['id']
                                        ]
                                    ),
                                    'label' => __('View')
                                ],
                            ];
                        }
                    }
                }

                return $dataSource;
            }

            /**
             * Get instance of escaper.
             *
             * @return Escaper
             * @deprecated
             */
            private function getEscaper()
            {
                if (!$this->escaper) {
                    $this->escaper = ObjectManager::getInstance()->get(Escaper::class);
                }

                return $this->escaper;
            }
        }

Screenshot :

Leave a comment

Your email address will not be published. Required fields are marked *