Go to : Store -> Attributes -> Product -> Edit attribute
I want to add custom dropdown as like Used in Product Listing dropdown.
I added it. But, It's display in Properties tab instead of Storefront Properties tab.
Please help me how to add that in Properties tab.
I upload my code and screenshot here.
CompanyName\ModuleName\Block\Adminhtml\Product\Attribute\Edit\Tab\Front.php
<?php
namespace CompanyName\ModuleName\Block\Adminhtml\Product\Attribute\Edit\Tab;
class Front extends \Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Front
{
protected function _prepareForm()
{
parent::_prepareForm();
$attributeObject = $this->_coreRegistry->registry('entity_attribute');
$form = $this->_formFactory->create(
['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
);
$yesnoSource = $this->_yesNo->toOptionArray();
$fieldset = $form->addFieldset(
'front_fieldset',
['legend' => __('Storefront Properties'), 'collapsable' => $this->getRequest()->has('popup')]
);
$fieldset->addField(
'used_in_custom',
'select',
[
'name' => 'used_in_custom',
'label' => __('Used in Custom'),
'title' => __('Used in Custom'),
'note' => __('Depends on design theme.'),
'values' => $yesnoSource,
]
);
$this->setForm($form);
return \Magento\Backend\Block\Widget\Form\Generic::_prepareForm();
}
}
CompanyName/ModuleName/view/adminhtml/ui_component/product_attribute_add_form.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="front_fieldset">
<field name="used_in_custom" sortOrder="130" formElement="checkbox">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="default" xsi:type="number">1</item>
</item>
</argument>
<settings>
<notice translate="true">Depends on design theme.</notice>
<dataType>boolean</dataType>
<label translate="true">Used in Custom</label>
<dataScope>used_in_custom</dataScope>
</settings>
<formElements>
<checkbox>
<settings>
<valueMap>
<map name="false" xsi:type="number">0</map>
<map name="true" xsi:type="number">1</map>
</valueMap>
<prefer>toggle</prefer>
</settings>
</checkbox>
</formElements>
</field>
</fieldset>
</form>
Best Answer
Try via plugin method:
After run command : php bin/magento setup:di:compile