Custom "Catalog Input Type for Store Owner" for magento product attributes

Custom "Catalog Input Type for Store Owner" for magento product attributes

September 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Custom "Catalog Input Type for Store Owner" for magento product attributes

Extending Magento: Creating Custom “Catalog Input Type for Store Owner” Attributes

In Magento, attribute creation is a powerful way to customize product details without modifying core files directly. The built-in options like textfield/area, data, and boolean are quite basic. If you want more advanced functionality, such as the ability to validate YouTube URLs in your product attributes, you’ll need to create your own “Catalog Input Type for Store Owner”.

This guide will walk you through the process of creating a custom attribute type that accepts multiple YouTube URLs and transforms them into their respective IDs. We’ll follow Magento’s recommended MVC (Model-View-Controller) style so we don’t have to edit any core files.

Understanding Magento Attribute Types

In Magento, attributes are created in the backend under Stores > Attributes > Product. Each attribute has a type that determines its behavior:

  • Text Field: A simple text input
  • Text Area: A multi-line text field
  • Data: Pulls data from an admin-defined source (like categories)
  • Boolean: Yes/No switch

To create more complex fields, we need to extend the core Varien_Data_Form_Element_Abstract class. This is where our custom YouTube URL field will live.

Creating a Custom Magento Attribute Type

  1. Create the Attribute Model: The attribute model extends Mage_Eav_Model_Entity_Attribute. Create a file in your module directory, for example, app/code/local/Vendor/Module/Model/Eav/Entity/Attribute/Youtube.php.
class Vendor_Module_Model_Eav_Entity_Attribute_Youtube
extends Mage_Eav_Model_Entity_Attribute_Abstract
{
    public function _construct()
    {
        $this->setType('varchar');
        $this->setBackend(new Vendor_Module_Model_Eav_Backend_Youtube());
        parent::_construct();
    }
}
  1. Create the Backend Model: The backend model handles data storage and retrieval in the database. Create a file app/code/local/Vendor/Module/Model/Eav/Backend/Youtube.php.
class Vendor_Module_Model_Eav_Backend_Youtube extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
    public function afterSave($object)
    {
        $urls = explode(',', $this->getValue($object));
        $ids = [];
        foreach ($urls as $url) {
            preg_match('/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/', $url, $matches);
            if (!empty($matches[2])) {
                $ids[] = $matches[2];
            }
        }

        // Save the IDs back to the attribute
        $this->setValue($object, implode(',', $ids));
    }
}
  1. Register the Attribute: In app/code/local/Vendor/Module/etc/config.xml, register your new attribute:
<global>
    <resources>
        <vendor_module_setup>
            <setup>
                <module>Vendor_Module</module>
            </setup>
        </vendor_module_setup>
    </resources>
    <helpers>
        <vendor_module>
            <class>Vendor_Module_Helper_Data</class>
        </vendor_module>
    </helpers>
    <models>
        <eav>
            <class>Mage_Eav_Model</class>
            <resourceModel>magentocommerce_eav_mysql4</resourceModel>
        </eav>
        <vendor_module>
            <class>Vendor_Module_Model</class>
            <resourceModel>vendor_module/resource_eav_mysql4</resourceModel>
        </vendor_module>
    </models>
    <events>
        <eav_setup_adding_attributes_to_set_collection>
            <observers>
                <vendor_module_add_youtube_attribute>
                    <type>singleton</type>
                    <class>Vendor_Module_Model_Observer</class>
                    <method>addYoutubeAttributeToSet</method>
                </Vendor_Module_Add_Youtube_Attribute>
            </observers>
        </eav_setup_adding_attributes_to_set_collection>
    </events>
</global>
  1. Create the Observer: In app/code/local/Vendor/Module/Model/Observer.php, create an observer to add your attribute to default sets:
class Vendor_Module_Model_Observer
{
    public function addYoutubeAttributeToSet($observer)
    {
        $eavSetup = Mage::getSingleton('eav/setup');
        $eavSetup->addAttribute(
            'catalog_product',
            'youtube_urls',
            [
                'label' => 'YouTube URLs (comma-separated)',
                'input' => 'text',
                'type' => 'varchar',
                'length' => 255,
                'backend_model' => 'Vendor_Module/Model/Eav/Backend/Youtube',
                'source_model' => '',
                'default_value' => '',
            ]
        );
    }
}

With these steps, you have successfully created a new “Catalog Input Type for Store Owner” attribute that accepts multiple YouTube URLs and transforms them into their respective IDs. This custom attribute lives within the Magento MVC architecture without modifying any core files.

For more information on Magento attribute creation and validation techniques, consider exploring our comprehensive guide to Magento 2 Attribute Customization Techniques at Laravel Company.

Catalog Extensions Admin

Our network