1

I have been trying to get this right for a bit, but when I look at the adminhtml_head block I see that it extends off the html_head block. I have extended the html_head block so that I could add a cdn item. It works just fine on the front when I adjust the layout xml, but when I adjust the layout xml for the back end it skips over extended class, so the overwrite doesn't work. Basically what I've done is test it by added a javascript to the adminhtml/page_head and that works using the normal add_js type. But when I go to use the cdn_js type, since it's not hitting my method, it just skips it.

Is there any reason that the admin would not be picking up my over write even thou both the admin end up extending off the core Mage_Page_Block_Html_Head ?

In my config I have this

<blocks>
<page>
<rewrite>
    <html_head>Wsu_Storeutilities_Block_Html_Head</html_head>
</rewrite>
</page>
</blocks>

Which works for the front. I have tried many different combinations to get the adminhtml to pick up as well with no luck.

3

The default head block in the backend is an instance of Mage_Adminhtml_Block_Page_Head (adminhtml/page_head). You need to override that also and add your method.
Even if Mage_Adminhtml_Block_Page_Head extends Mage_Page_Block_Html_Head and you've overwritten Mage_Page_Block_Html_Head the block used in the backend still extends the original Magento class, and your methods is not present in it.
[EDIT]
Your blocks rewrite section should look like this:

<blocks>
    <page><!-- rewrite the frontend head block -->
        <rewrite>
            <html_head>Wsu_Storeutilities_Block_Html_Head</html_head>
        </rewrite>
    </page>
    <adminhtml><!-- rewrite admin head block -->
        <rewrite>
            <page_head>Wsu_Storeutilities_Block_Adminhtml_Page_Head</page_head>
        </rewrite>
    </adminhtml>
</blocks>

Then create the file Wsu/Storeutilities/Block/Adminhtml/Page/Head.php with this content:

<?php
class Wsu_Storeutilities_Block_Adminhtml_Page_Head extends Mage_Adminhtml_Block_Page_Head{
    //your methods here
}
  • See I went down that rount and never got a change. I made the Adminhtml folder, changed the class name and added <page> <rewrite> <html_head>Wsu_Storeutilities_Block_Html_Head</html_head> <adminhtml_head>Wsu_Storeutilities_Block_Adminhtml_Head</adminhtml_head> </rewrite> </page> but I didn't see a change. I'm still trying to play with it and get it working. – jeremy.bass Jul 22 '13 at 20:30
  • I've edited my answer and added some other info. – Marius Jul 22 '13 at 20:36
  • you were write, I was pushing down the wrong path. Thank you I now have it working – jeremy.bass Jul 22 '13 at 20:50
0

It sounds like you don't quite understand how Magento class rewrites work — but don't worry, it's an easy enough thing to be confused about.

PHP's object system doesn't have a ruby/python like duck-typing/money-patching system. That means Magento only allows you to rewrite a directly instantiated class.

That is, when a block object in instantiated with a factory method (which looks something like this)

$layout->createBlock('page/html_head');

Magento will scan the configuration and look for a <page/> node with a <rewrite/> child node. If it finds one, it will look inside the <rewrite/> node for a <html_head/> node. If it finds a class inside that node, it will instantiate the object using that class instead.

So, in the admin console application, the head block is instantiated with something like this

$layout->createBlock('adminhtml/page_head')

This means the admin console will ignore your class rewrite, since your configuration only rewrites the page/html_head block.

Long story short: You need a second class rewrite for the adminhtml/page_head block.

  • you are right here I was pushing down the wrong path. tk – jeremy.bass Jul 22 '13 at 20:50

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.