0

Just installed Magento CE 1.9.3.1 into my local system.

Then I tried to override the default text input field of Varien class just to add "placeholder" attribute.

etc/config.xml of my module:

<?xml version="1.0"?>
<config>
 <modules>
 <Custom_PlaceholderAttribute>
 <version>1.0.0</version>
 </Custom_PlaceholderAttribute>
 </modules>
 <global>
 <blocks>
 <placeholderattr>
 <rewrite>
 <text>Varien_Data_Form_Element_Text</text>
 </rewrite>
 </placeholderattr>
 </blocks>
 </global>
</config>

Block class file of module:

<?php
class Custom_PlaceholderAttribute_Block_Adminhtml_Text extends Varien_Data_Form_Element_Text {
 public function getHtmlAttributes() {
 $attributes = parent::getHtmlAttributes();
 $attributes[] = 'placeholder';
 return $attributes;
 }
}

Now when I try to change fieldset type, in any block-form file, by adding below line, it is giving me Fatal Error.

$fieldset->addType('text', Mage::getConfig()->getBlockClassName('placeholderattr/adminhtml_text'));

The Fatal error I am getting is:

Fatal error: Class 'Mage_Placeholderattr_Text_Block_Adminhtml_Text' not found in C:\UwAmp\www\testmage1931\lib\Varien\Data\Form\Abstract.php on line 146

But if I try this, rewrite works fine:

$fieldset->addType('text','Custom_PlaceholderAttribute_Block_Adminhtml_Text');

Why block type doesn't work in getBlockClassName(), can somebody clarify/explain the reason for this ?

asked Feb 4, 2017 at 21:46

2 Answers 2

1

Add following code inside global tag

<blocks>
 <placeholderattr>
 <class>Custom_PlaceholderAttribute_Block_Block</class>
 </placeholderattr>
</blocks>

So your code looks like:

<config>
 <modules>
 <Custom_PlaceholderAttribute>
 <version>1.0.0</version>
 </Custom_PlaceholderAttribute>
 </modules>
 <global>
 <blocks>
 <placeholderattr>
 <class>Custom_PlaceholderAttribute_Block_Block</class>
 </placeholderattr>
 </blocks>
 </global>
</config>

Clear cache.

answered Feb 5, 2017 at 2:43
0

It is not a regular block you are trying to rewrite. You try to rewrite a lib.

Therefore you have to copy this class into the local codepool to do a rewrite. Have a look at this answer from Alan Storm: https://stackoverflow.com/a/6077165

In general, this guide will help you with all the rewrite types you might need: http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.