Categories
Magento

How to Hide Ui Component Form Custom Tab in Admin in Magento2

In this article, we will learn how to add/remove tab according to condition in magento2. As per previous blog we create custom tab and load ui grid on it. Now to hide that tab we’ll follow some steps:

Create customer_form.xml file at app/code/Vendor_Name/Module_Name/view/adminhtml/layout/customer_index_edit.xml

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="demo-amit-tab" class="Vendor_Name\Module_Name\Ui\Component\Form\Product\Action">
        <settings>
            <collapsible>false</collapsible>
            <label translate="true">Demo Tab</label>
            <componentType>fieldset</componentType>
            <additionalClasses>
                <class name="customer-warranty-form">true</class>
            </additionalClasses>
        </settings>

        <insertListing name="product_listing">
            <settings>
                <dataLinks>
                    <exports>false</exports>
                    <imports>true</imports>
                </dataLinks>
                <externalProvider>product_listing.product_listing_data_source</externalProvider>
                <selectionsProvider>product_listing.product_listing.product_columns.ids</selectionsProvider>
                <autoRender>true</autoRender>
                <dataScope>product_listing</dataScope>
                <ns>product_listing</ns>
                <exports>
                    <link name="parent_id">${ $.externalProvider }:params.parent_id</link>
                </exports>
                <imports>
                    <link name="parent_id">${ $.provider }:data.customer.entity_id</link>
                    <link name="onAction">ns = ${ $.ns }, index = actions:action</link>
                    <link name="onMassAction">ns = ${ $.ns }, index = listing_massaction:massaction</link>
                </imports>
            </settings>
        </insertListing>
    </fieldset>
</form>

Create Action.php file at Vendor_Name\Module_Name\Ui\Component\Form\Product\Action.php

<?php
use Magento\Ui\Component\Listing\Columns\Column;
class Action extends Column
{
    public function prepare()
    {
        if ($condition) { // Your condition goes here
            $status = true;
        }
        $this->_data['config']['componentDisabled'] = $status; // for removing the tab
        parent::prepare();
    }
}

I hope this blog is resolve your issue easily.
If you still have any issue feel free to ask and let us know your views to make the better. Share this solution with your other Magento buddies via social media.

Thanks for reading.

Leave a Reply

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