how to override adminhtml block for a function?
-
02-01-2021 - |
문제
Urapidflow has an issue which casued by a security patch and even their new version does not resolve the issue, the path for module file that I want to write an override is:
app\code\community\Unirgy\RapidFlow\Block\Adminhtml\Profile\Edit\Tab\Upload.php
anyways I have to rewrite the following:
$this->getUploader()->getConfig()
this should be
$this->getUploader()->getUploaderConfig()
to work fine. here is the module path: Unirgy_RapidFlow_Block_Adminhtml_Profile_Edit_Tab_Upload
I am creating a module to rewrite the functions inside it, here is what I did:
app\code\local\Scosche\Unirgy\etc\config.xml
<config>
<modules>
<Scosche_Unirgy>
<version>0.0.1</version>
</Scosche_Unirgy>
</modules>
<global>
<blocks>
<scosche_unirgy>
<class>Scosche_Unirgy_Block</class>
</scosche_unirgy>
<unirgy_rapidFlow>
<rewrite>
<adminhtml_profile_edit_tab_upload>Scosche_Unirgy_Block_Adminhtml_Profile_Edit_Tab_Upload</adminhtml_profile_edit_tab_upload>
</rewrite>
</unirgy_rapidFlow>
</blocks>
</global>
</config>
This is wrong for some reason I created the same folders and path on scosche module but although I can see module is active in Advanced configuration, it is not working, app\code\community\Unirgy\RapidFlow\etc\config.xml:
<blocks>
<urapidflow><class>Unirgy_RapidFlow_Block</class></urapidflow>
</blocks>
해결책
As discussed in the comments, one common mistake is the assumption that for example a model or block rewrite is to be done based on Vendor_Modulename
.
This means, to create a proper rewrite for a core and/or a third party module the one must take a look at the modules etc/config.xml
and find the actual alias/identifier that is defined for the model or block in question.
A basic example:
In case you want to rewrite a certain method of app/code/core/Mage/Catalog/Block/Product.php
you'll first have to check in app/code/core/Mage/Catalog/etc/config.xml
to find something like this:
<config>
[...]
<global>
[...]
<blocks>
<catalog> <!-- this is our node of interest -->
<class>Mage_Catalog_Block</class>
</catalog>
</blocks>
[...]
</global>
[...]
</config>
This tells us, that our rewrites must be based on catalog
(rather than mage_catalog
or anything else). This then will allow us to rewrite a block class in our custom module by setting up something like the following:
<config>
[...]
<global>
[...]
<blocks>
<catalog> <!-- based on what we found in app/code/core/Mage/Catalog/etc/config.xml/ -->
<rewrite>
<product>Vendor_Module_Block_Product</product>
</rewrite>
</catalog>
</blocks>
[...]
</global>
[...]
</config>