Reputation: 5135
I created a module that used a custom widget/grid/column for my admin grid to display a thumbnail image and everything worked. Now I need to create another module in the same project that does the same thing, but the image column will not work. It appears like its not even loading my new class, since it won't execute any stmt I put into the file. I know its properly loading data, b/c if I change the type to text, then the correct info from the DB is populated into the field. But when I change to my new 'image' type the cell is empty. does anyone know why it wouldn't be working?
ABT/Background/etc/config.xml << doesn't work
<global>
....
<blocks>
<background>
<class>ABT_Background_Block</class>
</background>
<adminhtml>
<rewrite>
<widget_grid_column>ABT_Background_Block_Widget_Grid_Column</widget_grid_column>
</rewrite>
</adminhtml>
</blocks>
....
</global>
the module I copied to get me up and running has the exact same config setup, but yet it works fine ABT/Feature/etc/config.xml << this works correctly
<global>
....
<blocks>
<feature>
<class>ABT_Feature_Block</class>
</feature>
<adminhtml>
<rewrite>
<widget_grid_column>ABT_Feature_Block_Widget_Grid_Column</widget_grid_column>
</rewrite>
</adminhtml>
</blocks>
....
</global>
Upvotes: 1
Views: 1546
Reputation: 4769
I'm not sure to have got your setup correctly.
Anyway, it looks like you have two override rules on the same class Widget_Grid_Column
. The last module loaded is the ABT_Feature
so the rule of that block overwrite the rule of the ABT_Background
module.
You have two solutions:
ABT_Feature_Block_Widget_Grid_Column
class will extend the ABT_Background_Block_Widget_Grid_Column
. Upvotes: 1
Reputation: 166046
Here's what happening with Magento when you rewrite a class.
When Magento instantiates a Block class, it uses code something like the following
$this->getLayout()->createBlock('adminhtml/widget_grid_column')
The createBlock
method is a factory. Magento uses the identifier
adminhtml/widget_grid_column
to lookup which class should be instantiated. By default, that's
Mage_Adminhtml_Block_Widget_Grid_Column
When you create your rewrite, you're telling Magento
Hey. instead of using 'Mage_Adminhtml_Block_Widget_Grid_Column' for a 'adminhtml/widget_grid_column', you should use 'ABT_Background_Block_Widget_Grid_Column'
This means that, for any given system, a class may only be rewritten once. In the code you're showing above, you're trying to rewrite the class twice. Only one of your rewrites will win.
The quick approach I'd take is to keep all your customizations in a single override class.
More generally, I try to avoid using rewrites if at all possible. They're a powerful system, but should be using sparingly. I haven't done much grid customizing, but the general approach I'd try to take would be to change the adminhtml layout to instantiate a new grid class from my custom module that extends an existing grid class, which in turn may use custom column classes.
More work up front, but once you've figured it out you can use the technique over and over again, and not worry abou conflicts from a rewrite.
Upvotes: 2