Skip to content

Instantly share code, notes, and snippets.

@jacquesbh
Last active December 10, 2015 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacquesbh/4401568 to your computer and use it in GitHub Desktop.
Save jacquesbh/4401568 to your computer and use it in GitHub Desktop.
<?php
Zend_Debug::dump(Mage::app()->getLayout()->getUpdate()->getHandles());
<?php
abstract class Mage_Core_Controller_Varien_Action
{
/* .. */
/**
* Load layout by handles(s)
*
* @param string $handles
* @param string $cacheId
* @param boolean $generateBlocks
* @return Mage_Core_Controller_Varien_Action
*/
public function loadLayout($handles=null, $generateBlocks=true, $generateXml=true)
{
// if handles were specified in arguments load them first
if (false!==$handles && ''!==$handles) {
// The $handles can be a string or an array
$this->getLayout()->getUpdate()->addHandle($handles ? $handles : 'default');
}
/*
* Add default layout handles for this action
*/
//$this->addActionLayoutHandles();
// -- copy of addActionLayoutHandles() --
$update = $this->getLayout()->getUpdate();
// load store handle
$update->addHandle('STORE_'.Mage::app()->getStore()->getCode());
// load theme handle
$package = Mage::getSingleton('core/design_package');
$update->addHandle('THEME_'.$package->getArea().'_'.$package->getPackageName().'_'.$package->getTheme('layout'));
// load action handle
// The method getFullActionName() returns "frontname_controller_action" in our example
$update->addHandle(strtolower($this->getFullActionName()));
// -- endcopy of addActionLayoutHandles() --
/*
* Load the updates of the Layout
*/
//$this->loadLayoutUpdates();
// -- copy of loadLayoutUpdates() --
// dispatch event for adding handles to layout update
Mage::dispatchEvent(
'controller_action_layout_load_before',
array('action'=>$this, 'layout'=>$this->getLayout())
);
// load layout updates by specified handles
$this->getLayout()->getUpdate()->load();
// -- endcopy of loadLayoutUpdates() --
if (!$generateXml) {
return $this;
}
$this->generateLayoutXml();
if (!$generateBlocks) {
return $this;
}
$this->generateLayoutBlocks();
$this->_isLayoutLoaded = true;
return $this;
}
/* .. */
}
<?php
class Mon_Module_Model_Observer
{
/**
* Add handles before the layout xml generation
* @param Varien_Event_Observer $observer
* @return void
*/
public function layoutLoadBefore(Varien_Event_Observer $observer)
{
if ($action = $observer->getAction()) {
Mage::dispatchEvent(
'controller_action_layout_load_before_' . $action->getFullActionName(),
$observer->getData()
);
}
}
}
<?php
class Mon_Module_Model_Observer
{
/**
* Add handles before the layout xml generation
* @param Varien_Event_Observer $observer
* @return void
*/
public function layoutLoadBefore(Varien_Event_Observer $observer)
{
if ($action = $observer->getAction()) {
switch ($action->getFullActionName()) {
case 'frontname_controller_action':
$observer->getLayout()->getUpdate()->addHandle('MON_NEW_HANDLE');
break;
}
}
}
}
<?php
class Mon_Module_Model_Observer
{
/**
* Add handles before the layout xml generation
* @param Varien_Event_Observer $observer
* @return void
*/
public function layoutLoadBefore(Varien_Event_Observer $observer)
{
if ($action = $observer->getAction()) {
switch ($action->getFullActionName()) {
case 'frontname_controller_action':
$news = Mage::registry('current_news');
if ($news->getId()) {
$observer->getLayout()->getUpdate()->addHandle('MON_MODULE_ACTION_NEWS_TYPE_' . $news->getType());
}
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment