I am trying to add a field to the attribute information section. This should be an text field for multistore ( just like the manage titles section).
Magento version: 2.2.6
Here’s what I got now:
- I created a custom module.
- A plugin:
appcodeCustomModulePluginBlockAdminhtmlProductAttributeEditTabfront.php
use MagentoFrameworkDBDdlTable;
class Front
{
/**
* @param MagentoConfigModelConfigSourceYesno $yesNo
*/
protected $scopeConfig;
public function __construct(
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}
public function aroundGetFormHtml(
MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront $subject,
Closure $proceed
)
{
$form = $subject->getForm();
$fieldset = $form->getElement('front_fieldset');
$fieldset->addField(
'label_field',
'text',
[
"type" => Table::TYPE_TEXT,
'name' => 'label_field',
'label' => __('Label field'),
'title' => __('label_field'),
'note' => __('label_field'),
'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_GLOBAL,
'translate' => 'label',
"nullable" => true,
'system' => 0,
]
);
return $proceed();
}
}
And I also created A upgradeschema to create the field in the catalog_eav_attribute table;
class UpgradeSchema implements UpgradeSchemaInterface
{
/**
* {@inheritdoc}
*/
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
$installer->getConnection()->addColumn(
$installer->getTable('catalog_eav_attribute'),
'label_field',
[
'type' => Table::TYPE_TEXT,
'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_GLOBAL,
"nullable" => true,
'default' => '',
'comment' => 'label field',
"system" => 0,
'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
]
);
$installer->endSetup();
}
}
The field is created in attribute information -> Frontend properties aswell as the column in the db.
Also the value is being saved but I am not able to see it in the backend.
The endgoal is to save the attribute as text ( preffered for multistore ) and show the value in a phtml file. I seem to be stuck at retrieving the data in the backend.
This is my first time asking a question so if any more / less info is needed let me know.