-
custom tab or magento core tab ?? – Rk Rathod May 24 '19 at 6:26
-
i want hidden custom tab – NewBie May 24 '19 at 6:28
-
you can delete tab also – Rk Rathod May 24 '19 at 6:28
-
No, i just want hidden it. – NewBie May 24 '19 at 6:29
-
because i have conditions – NewBie May 24 '19 at 6:30
You should be able to use the method isComponentVisible()
namespace Custom\Custom\Ui\Component\Form;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\ComponentVisibilityInterface;
use Magento\Ui\Component\Form\Fieldset;
/**
* Class Fieldset
* @package Custom\Custom\Ui\Component\Form
*/
class CustomFieldset extends Fieldset implements ComponentVisibilityInterface
{
/**
* CustomFieldset constructor.
* @param ContextInterface $context
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
array $components = [],
array $data = []
) {
$this->context = $context;
parent::__construct($context, $components, $data);
}
/**
* @return bool
*/
public function isComponentVisible(): bool
{
$visible = //add logic
return (bool)$visible;
}
}
And in your xml you just need to include this class in the fieldset
<fieldset name="custom" sortOrder="30" class="Custom\Custom\Ui\Component\Form\CustomFieldset">
-
This is only working in Tab Fieldset not in Normal fieldset. Do you have any idea to show hide Normal Fieldset by using php class? – Siranjeevi K S May 7 '20 at 9:58
-
In Tab File You Can Set Tab Visibility Like This :-
public function canShowTab()
{
return false;
}
public function isHidden()
{
return true;
}
In ui_component
It's just a demo
<fieldset name="design">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">false</item>
</item>
</argument>
</fieldset>
in your code what you need to hide just put like
<item name="visible" xsi:type="boolean">false</item>
There are two way to hide the fieldset based on condition.
Step 1: Override prepare method of your fieldset like below.
Your Form.xml
<fieldset name="menu_items" class="Vendor\Module\Ui\Component\Form\CustomFieldset">
<settings>
<collapsible>true</collapsible>
<label>Menu Items</label>
<visible>false</visible>
</settings>
<fieldset name="assign_applicants">
<settings>
<label>Menu Items</label>
<collapsible>true</collapsible>
</settings>
<field name="name" sortOrder="30" formElement="input">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">menu</item>
</item>
</argument>
<settings>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
</validation>
<dataType>string</dataType>
<label translate="true">Name</label>
<dataScope>name</dataScope>
</settings>
</field>
</fieldset>
</fieldset>
Prepare method of your component fieldset class CustomFieldset.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace VendorName\ModuleName\Ui\Component\Form;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\ComponentVisibilityInterface;
use Magento\Ui\Component\Form\Fieldset;
/**
* Class Fieldset
* @package VendorName\ModuleName\Ui\Component\Form
*/
class CustomFieldset extends Fieldset
{
/**
* @var \VendorName\ModuleName\Helper\Data
*/
protected $helper;
/**
* RuleInformationFieldset constructor.
* @param ContextInterface $context
* @param array $components
* @param array $data
* @param \VendorName\ModuleName\Helper\Data $helper
*/
public function __construct(
ContextInterface $context,
array $components = [],
array $data = [],
\VendorName\ModuleName\Helper\Data $helper
) {
parent::__construct($context, $components, $data);
$this->helper = $helper;
}
/**
* hide or show fieldset based on module enabled or disabled.
*/
public function prepare()
{
$visiable = false;
$config = $this->getData('config');
if( $this->helper->isModuleEnable() ) {
$visiable = true;
}
$config['visible'] = $visiable;
$this->setData('config', $config);
parent::prepare();
}
}
Step 2: You need to disable the whole fieldset then add the following code in your Data provider class.
/**
* Get meta function.
* return mixed
*/
public function getMeta()
{
$meta = parent::getMeta();
if($this->helper->isModuleEnable()) {
$meta['menu_items']['arguments']['data']['config']['visible'] = 1;
} else{
$meta['menu_items']['arguments']['data']['config']['visible'] = 0;
}
return $meta;
}
Hope it will help you.