I am attempting to add an additional category custom attribute to an existing module. A previous developer had already added two custom attributes and I am working on adding a third. I am able to get the third custom attribute to display in the backend but when I save any value inside the field, the new custom attribute does not save but I am able to modify the two existing custom attributes.
Any assistance to resolve this issue is appreciated.
InstallData.php
<?php
namespace WholeLatteLove\CategoryMedia\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Catalog\Model\Category;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* EAV setup factory
*
* @var EavSetupFactory
*/
private $eavSetupFactory;
/**
* Init
*
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
/**
* Add attributes to the eav/attribute
*/
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'header_img',
[
'type' => 'varchar',
'label' => 'Header Image',
'input' => 'image',
'backend' => 'Magento\Catalog\Model\Category\Attribute\Backend\Image',
'required' => false,
'sort_order' => 5,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'youtube_id',
[
'group' => 'General Information',
'type' => 'varchar',
'label' => 'YouTube ID',
'input' => 'text',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Varchar',
'sort_order' => 5,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'cinematic_img',
[
'type' => 'varchar',
'label' => 'Cinematic Image',
'input' => 'image',
'backend' => 'Magento\Catalog\Model\Category\Attribute\Backend\Image',
'required' => false,
'sort_order' => 5,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
]
);
}
}
category_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="catvideoattribute">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Youtube ID</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">100</item>
</item>
</argument>
<field name="youtube_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">1</item>
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">input</item>
<item name="label" xsi:type="string" translate="true">Youtube Video ID</item>
</item>
</argument>
</field>
</fieldset>
<fieldset name="headerimgattribute">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Header Image</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">101</item>
</item>
</argument>
<field name="header_img">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">2</item>
<item name="dataType" xsi:type="string">image</item>
<item name="formElement" xsi:type="string">input</item>
<item name="label" xsi:type="string" translate="true">Header Image</item>
</item>
</argument>
</field>
</fieldset>
<fieldset name="cinematicimgattribute">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Cinematic Image</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">102</item>
</item>
</argument>
<field name="cinematic_img">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">3</item>
<item name="dataType" xsi:type="string">image</item>
<item name="formElement" xsi:type="string">input</item>
<item name="label" xsi:type="string" translate="true">Cinematic Image</item>
</item>
</argument>
</field>
</fieldset>