l'extension de la tête html pour frontend ne fonctionne pas pour la fin de retour?

magento.stackexchange https://magento.stackexchange.com/questions/5955

  •  16-10-2019
  •  | 
  •  

Question

J'ai essayé d'obtenir ce droit pour un peu, mais quand je regarde le bloc adminhtml_head je vois qu'il étend sur le bloc de html_head. J'ai étendu le bloc html_head pour que je puisse ajouter un élément de cdn. Il fonctionne très bien à l'avant quand je régler le xml de mise en page, mais quand j'ajuste la mise en page XML pour la fin arrière, il saute sur la classe étendue, de sorte que le Ecraser ne fonctionne pas. En fait ce que je l'ai fait est le test par un javascript ajouté à la adminhtml / page_head et que les travaux en utilisant le type de add_js normal. Mais quand je vais utiliser le type de cdn_js, car il est ne pas frapper ma méthode, il saute juste.

Y at-il des raisons que l'administrateur ne serait pas ramasser mon écriture sur toi aussi à la fois la fin d'administration en extension de l'Mage_Page_Block_Html_Head de base?

Dans ma config j'ai cette

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

Ce qui fonctionne pour l'avant. J'ai essayé beaucoup de combinaisons différentes pour obtenir le adminhtml pour ramasser aussi bien avec pas de chance.

Était-ce utile?

La solution

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
}

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top