Setep: 1. Add this file in Block folder
Vender\Module\Block\Adminhtml\Index\Edit\Tab
namespace Vender\Module\Block\Adminhtml\Index\Edit\Tab;
use Magento\Framework\App\ObjectManager;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;
class Conditions extends Generic implements TabInterface
{
/**
* Core registry
*
* @var \Magento\Backend\Block\Widget\Form\Renderer\Fieldset
*/
protected $_rendererFieldset;
/**
* @var \Magento\Rule\Block\Conditions
*/
protected $_conditions;
private $ruleFactory;
/**
* Initialize dependencies.
*
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param \Magento\Rule\Block\Conditions $conditions
* @param \Magento\Backend\Block\Widget\Form\Renderer\Fieldset $rendererFieldset
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Rule\Block\Conditions $conditions,
\Magento\Backend\Block\Widget\Form\Renderer\Fieldset $rendererFieldset,
array $data = []
) {
$this->_rendererFieldset = $rendererFieldset;
$this->_conditions = $conditions;
parent::__construct($context, $registry, $formFactory, $data);
}
private function getRuleFactory()
{
if ($this->ruleFactory === null) {
$this->ruleFactory = ObjectManager::getInstance()->get('Magento\CatalogRule\Model\RuleFactory');
}
return $this->ruleFactory;
}
/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
public function getTabClass()
{
return null;
}
/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
public function getTabLabel()
{
return __('Conditions');
}
/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
public function getTabTitle()
{
return __('Conditions');
}
/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
public function canShowTab()
{
return true;
}
/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
public function isHidden()
{
return false;
}
protected function _prepareForm()
{
$model = $this->_coreRegistry->registry('\Magento\CatalogRule\Controller\RegistryConstants::CURRENT_CATALOG_RULE_ID');
if (!$model) {
$id = $this->getRequest()->getParam('rule_id');
$model = $this->getRuleFactory()->create();
$model->load($id);
}
$fieldsetId = 'conditions_fieldset';
$formName = 'catalog_rule_form';
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('rule_');
$newChildUrl = $this->getUrl(
'catalog_rule/promo_catalog/newConditionHtml/form/' . $model->getConditionsFieldSetId($formName),
['form_namespace' => $formName]
);
$renderer = $this->_rendererFieldset->setTemplate('Magento_CatalogRule::promo/fieldset.phtml')
->setNewChildUrl($newChildUrl)
->setFieldSetId($model->getConditionsFieldSetId($formName));
$fieldset = $form->addFieldset(
$fieldsetId,
[
'legend' => __(
'Apply the rule only if the following conditions are met (leave blank for all products).'
)
]
)->setRenderer(
$renderer
);
$fieldset->addField(
'conditions',
'text',
['name' => 'conditions', 'label' => __('Conditions'), 'title' => __('Conditions')]
)->setRule(
$model
)->setRenderer(
$this->_conditions
);
$form->setValues($model->getData());
$this->setConditionFormName($model->getConditions(), $formName);
$this->setForm($form);
return parent::_prepareForm();
}
}
Step: 2 Add this code in layout edit file
frontendname_index_edit.xml
<referenceContainer name="left">
<block class="Vender\Module\Block\Adminhtml\Chartlist\Edit\Tabs" name="vender_module_edit_tabs">
<block class="Vender\Module\Block\Adminhtml\Chartlist\Edit\Tab\Conditions" name="vender_module_tab_conditions"/>
<action method="addTab">
<argument name="name" xsi:type="string">conditions_section</argument>
<argument name="block" xsi:type="string">vender_module_tab_conditions</argument>
</action>
</block>
</referenceContainer>