1

I'm trying to rewrite Mage_Adminhtml_Cms_Wysiwyg_ImagesController to override its indexAction(). I seem to be able to rewrite it successfully as the request is being routed to it, but I've been unable to load layout in the action.

config.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <Mynamespace_Mymodule>
      <version>0.1.0</version>
    </Mynamespace_Mymodule>
  </modules>
  <global>
    <blocks>
      <mynamespace_mymodule>
        <class>Mynamespace_Mymodule_Block</class>
      </mynamespace_mymodule>
    </blocks>
  </global>
  <admin>
    <routers>
        <adminhtml>
          <use>admin</use>
          <args>
            <modules>
              <Mynamespace_Mymodule before="Mage_Adminhtml">Mynamespace_Mymodule_Adminhtml</Mynamespace_Mymodule>
            </modules>
          </args>
        </adminhtml>
    </routers>
  </admin>
  <adminhtml>
        <layout>
            <updates>
                <mynamespace_mymodule>
                    <file>mynamespace/mymodule.xml</file>
                </mynamespace_mymodule>
            </updates>
        </layout>
  </adminhtml>
</config>

mymodule.xml (layout file):

<?xml version="1.0"?>
<layout version="0.1.0">
    <mynamespace_mymodule_adminhtml_cms_wysiwyg_images_index>
        <update handle="adminhtml_cms_wysiwyg_images_index" />
        <reference name="content">
            <block name="mynamespace_mymodule.content" 
                type="mynamespace_mymodule/cms_wysiwyg_images_content" 
                template="cms/browser/content.phtml"
            />
        </reference>
    </mynamespace_mymodule_adminhtml_cms_wysiwyg_images_index>
</layout>

The controller is instantiated but the block class isn't.

Calling $this->getLayout()->getUpdate()->getHandles() in the controller action results in an empty array; it doesn't seem to have any handles.

Why might this be the case and what should I do to get the handles loaded?

1 Answer 1

1

Based on the layout XML you shared, the problem is with the handle:

mynamespace_mymodule_adminhtml_cms_wysiwyg_images_index

Should be named

adminhtml_cms_wysiwyg_images_index

Generated layout handles are not concerned with the namespace and module parts. When you call $this->loadLayout() in a controller action, you will trigger this code:

# File: app/code/core/Mage/Core/Controller/Varien/Action.php
public function loadLayout($handles=null, $generateBlocks=true, $generateXml=true)
{
    ...

    // add default layout handles for this action
    $this->addActionLayoutHandles();

    $this->loadLayoutUpdates();

    ...
}

Where addActionLayoutHandles will add a handle via getFullActionName method in the same file:

public function getFullActionName($delimiter='_')
{
    return $this->getRequest()->getRequestedRouteName().$delimiter.
        $this->getRequest()->getRequestedControllerName().$delimiter.
        $this->getRequest()->getRequestedActionName();
}

So, when you attempt to dump the handles, expect that the above type of handle would be there. You said you're getting nothing, or an empty array. Have you actually loaded the layout ($this->loadLayout()) before inspecting the handles?

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.