1

I added category attribute (textarea) and Magento stops displaying WYSIWYG button if I use custom renderer for that textarea field. I want to ask I anyone knows why this happens?

Here are my steps. I added category attribute, a simple textarea with WYSIWYG button:

$installer->addAttribute('catalog_category', 'my_attr1', array(
    'label'             => 'My attribute 1',
    'type'              => 'text',
    'input'             => 'textarea',
    'visible_on_front'  => true,
    'wysiwyg_enabled'   => true,
    'is_html_allowed_on_front' => true,
    'visible'           => true,
    'required'          => false,
    'backend'           => '',
    'frontend'          => '',
    'searchable'        => false,
    'filterable'        => false,
    'comparable'        => false,
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));

All works correct, WYSIWYG button is displayed below the field.

Then I added second attribute my_attr2 to make some tests. That second attribute use my custom renderer class (see 'input_renderer' => 'my_custom') because I need to extend that field with additional functionality. I checked that attribute was added correct and works 100% correct. That class My_Custom extends Magento's default textarea renderer Varien_Data_Form_Element_Textarea so it looks and works exactly the same as standard textarea field.

But for some reason Magento stops displaying WYSIWYG button if I use custom renderer.

$installer->addAttribute('catalog_category', 'my_attr2', array(
    'label'             => 'My attribute 2',
    'type'              => 'text',
    'input'             => 'textarea',
    'input_renderer'    => 'my_custom', //<---custom
    'visible_on_front'  => true,
    'wysiwyg_enabled'   => true,
    'is_html_allowed_on_front' => true,
    'visible'           => true,
    'required'          => false,
    'backend'           => '',
    'frontend'          => '',
    'searchable'        => false,
    'filterable'        => false,
    'comparable'        => false,
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));

Here's the rendered class (located in file lib/My/Custom.php). I checked that Magento for sure use this class when rendering the second attribute (I added logging to the constructor to make sure it works).

<?php
class My_Custom extends Varien_Data_Form_Element_Textarea
{
    public function __construct($attributes=array())
    {
        parent::__construct($attributes);
        Mage::log("My_Custom is working");
    }
}

Even If I remove all the code from the renderer class lib/My/Custom.php to make sure I didn't break or override anything, the WYSIWYG button is still not displayed below the second attribute:

<?php
class My_Custom extends Varien_Data_Form_Element_Textarea
{
}

And as soon as I update my_attr2 and remove the custom renderer class, then the WYSIWYG button is displayed correct below the textarea (just like it should be).

  • Try to make your renderer extend Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg – Marius Jun 3 '14 at 11:11
  • @Marius Thank you very much. Please post it so that I can accept it as an answer. – d3tr5845 Jun 3 '14 at 11:25
1

Your renderer should extend the Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg. That is the one used for rendering textareas in the category add/edit form.
You can see that from the method Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes::_getAdditionalElementTypes

protected function _getAdditionalElementTypes()
{
    return array(
        'image' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_category_helper_image'),
        'textarea' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_helper_form_wysiwyg')
    );
}

This means that for elements that don't have a specified renderer, the ones referred in this method are used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.