I have created a custom category select attribute to list active categories, after choosing a category from the list and saving there is an error message displayed “attribute value is empty. Set the attribute and try again” I have checked the values of the selected category it seems like good
Category_form.xml
<?xml version="1.0" ?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="general">
<field name="category_category_attribute" formElement="select" sortOrder="20">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">xxxxCustomCategoryAttributeModelConfigSourceCustomOptionList</item>
</argument>
<settings>
<dataType>text</dataType>
<label translate="true">Category</label>
<dataScope>category</dataScope>
</settings>
</field>
</fieldset>
</form>
Patch file
<?php
namespace xxxxCustomCategoryAttributeSetupPatchData;
use MagentoEavModelEntityAttributeScopedAttributeInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;
use MagentoCatalogModelCategory;
class CategoryAttribute implements DataPatchInterface
{
protected $_moduleDataSetup;
protected $_eavSetupFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
EavSetupFactory $eavSetupFactory
) {
$this->_moduleDataSetup = $moduleDataSetup;
$this->_eavSetupFactory = $eavSetupFactory;
}
public function apply()
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->_eavSetupFactory->create(['setup' => $this->_moduleDataSetup]);
$eavSetup->addAttribute(Category::ENTITY, 'category_category_attribute', [
'type' => 'int',
'label' => 'category list',
'input' => 'select',
'default' => '',
'source' => 'xxxxCustomCategoryAttributeModelConfigSourceCustomOptionList',
'sort_order' => 3,
'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
'visible_on_front' => true
]);
}
public static function getDependencies()
{
return [];
}
public function getAliases()
{
return [];
}
}