/** * Apply the layout action node for a block * * @param Mage_Core_Model_Layout_Element $node * @return Mage_Core_Model_Layout */ public function shim_generateAction($node) { if (!($parentNode = $node->getParent())) { $parentNode = new Varien_Object(); } return $this->_shim_getLayout()->_generateAction($node, $parentNode); }
public function shimGenerateBlock(Mage_Core_Model_Layout_Element $blockNode) { $layout = self::__getLayout(); if (!($parent = $blockNode->getParent())) { $parent = new Varien_Object(); } $layout->_generateBlock($blockNode, $parent); return $layout->generateBlocks($blockNode); }
/** * Validate node's declared position in hierarchy and add errors to the specified array if found * * @param SimpleXMLElement $node * @param Mage_Core_Model_Layout_Element $xml * @param array &$errors */ protected function _collectHierarchyErrors($node, $xml, &$errors) { $name = $node->getName(); $refName = $node->getAttribute('type') == Mage_Core_Model_Layout_Update::TYPE_FRAGMENT ? $node->getAttribute('owner') : $node->getAttribute('parent'); if ($refName) { $refNode = $xml->xpath("/layouts/{$refName}"); if (!$refNode) { $errors[$name][] = "Node '{$refName}', referenced in hierarchy, does not exist"; } elseif ($refNode[0]->getAttribute('type') == Mage_Core_Model_Layout_Update::TYPE_FRAGMENT) { $errors[$name][] = "Page fragment type '{$refName}', cannot be an ancestor in a hierarchy"; } } }
public function testPrepare() { $this->_model = new Mage_Core_Model_Layout_Element(__DIR__ . '/../_files/_layout_update.xml', 0, true); list($blockNode) = $this->_model->xpath('//block[@name="head"]'); list($actionNode) = $this->_model->xpath('//action[@method="setTitle"]'); $this->assertEmpty($blockNode->attributes()->parent); $this->assertEmpty($blockNode->attributes()->class); $this->assertEmpty($actionNode->attributes()->block); $this->_model->prepare(array()); $this->assertEquals('root', (string) $blockNode->attributes()->parent); $this->assertEquals('Mage_Adminhtml_Block_Page_Head', (string) $blockNode->attributes()->class); $this->assertEquals('head', (string) $actionNode->attributes()->block); }
/** * Get the default items * * @param Mage_Core_Model_Layout_Element $xml * @param string $method * @return array */ protected function _getDefaultItems($xml, $method) { $defaults = array(); foreach ($xml->children() as $handle => $node) { if ($handle !== 'default') { continue; } if ($actions = $node->xpath(".//action[@method='" . $method . "']")) { foreach ($actions as $action) { $defaults[] = (string) $action->script; } } } return array_unique($defaults); }
public function testPrepare() { /** * @TODO: Need to use ObjectManager instead 'new'. * On this moment we have next bug MAGETWO-4274 which blocker for this key. */ $this->_model = new Mage_Core_Model_Layout_Element(__DIR__ . '/../_files/_layout_update.xml', 0, true); list($blockNode) = $this->_model->xpath('//block[@name="head"]'); list($actionNode) = $this->_model->xpath('//action[@method="setTitle"]'); $this->assertEmpty($blockNode->attributes()->parent); $this->assertEmpty($blockNode->attributes()->class); $this->assertEmpty($actionNode->attributes()->block); $this->_model->prepare(array()); $this->assertEquals('root', (string) $blockNode->attributes()->parent); $this->assertEquals('Mage_Adminhtml_Block_Page_Head', (string) $blockNode->attributes()->class); $this->assertEquals('head', (string) $actionNode->attributes()->block); }
/** * Get the layout's XML structure * * This is cached because it's expensive to load for each ESI'd block * * @return Mage_Core_Model_Layout_Element|SimpleXMLElement */ public function getLayoutXml() { Varien_Profiler::start('turpentine::helper::esi::getLayoutXml'); if (is_null($this->_layoutXml)) { if ($useCache = Mage::app()->useCache('layout')) { $cacheKey = $this->getFileLayoutUpdatesXmlCacheKey(); $this->_layoutXml = simplexml_load_string(Mage::app()->loadCache($cacheKey)); } // this check is redundant if the layout cache is disabled if (!$this->_layoutXml) { $this->_layoutXml = $this->_loadLayoutXml(); if ($useCache) { Mage::app()->saveCache($this->_layoutXml->asXML(), $cacheKey, array('LAYOUT_GENERAL_CACHE_TAG')); } } } Varien_Profiler::stop('turpentine::helper::esi::getLayoutXml'); return $this->_layoutXml; }
/** * Filter and collect layout handles into array * * @param Mage_Core_Model_Layout_Element $layoutHandles */ protected function _collectLayoutHandles($layoutHandles) { if ($layoutHandlesArr = $layoutHandles->xpath('/*/*/label/..')) { foreach ($layoutHandlesArr as $node) { if ($this->_filterLayoutHandle($node->getName())) { $helper = Mage::helper(Mage_Core_Model_Layout::findTranslationModuleName($node)); $this->_layoutHandles[$node->getName()] = $helper->__((string) $node->label); } } asort($this->_layoutHandles, SORT_STRING); } }
/** * Check whether given block match allowed block types * * @param Mage_Core_Model_Layout_Element $block * @return boolean */ protected function _filterBlock($block) { if (!$this->getAllowedBlocks()) { return true; } if (in_array((string) $block->getAttribute('name'), $this->getAllowedBlocks())) { return true; } return false; }
/** * The actual recursive implementation of getChildBlockNames * * @param Mage_Core_Model_Layout_Element $blockNode * @return array */ protected function _getChildBlockNames($blockNode) { Varien_Profiler::start('turpentine::helper::data::_getChildBlockNames'); if ($blockNode instanceof Mage_Core_Model_Layout_Element) { $blockNames = array((string) $blockNode['name']); foreach ($blockNode->xpath('./block | ./reference') as $childBlockNode) { $blockNames = array_merge($blockNames, $this->_getChildBlockNames($childBlockNode)); if ($this->getLayout() instanceof Varien_Simplexml_Config) { foreach ($this->getLayout()->getNode()->xpath(sprintf('//reference[@name=\'%s\']', (string) $childBlockNode['name'])) as $childBlockLayoutNode) { $blockNames = array_merge($blockNames, $this->_getChildBlockNames($childBlockLayoutNode)); } } } } else { $blockNames = array(); } Varien_Profiler::stop('turpentine::helper::data::_getChildBlockNames'); return $blockNames; }
/** * Update args according to its type * * @param Mage_Core_Model_Layout_Element $node * @return array */ protected function _extractArgs($node) { $args = (array) $node->children(); unset($args['@attributes']); foreach ($args as $key => $arg) { if ($arg instanceof Mage_Core_Model_Layout_Element) { if (isset($arg['helper'])) { $args[$key] = $this->_getArgsByHelper($arg); } else { /** * if there is no helper we hope that this is assoc array */ $arr = $this->_getArgsFromAssoc($arg); if (!empty($arr)) { $args[$key] = $arr; } } } } if (isset($node['json'])) { $json = explode(' ', (string) $node['json']); foreach ($json as $arg) { $args[$arg] = Mage::helper('Mage_Core_Helper_Data')->jsonDecode($args[$arg]); } } return $args; }
/** * @dataProvider elementNameDataProvider */ public function testGetElementName($xml, $name) { $model = new Mage_Core_Model_Layout_Element($xml); $this->assertEquals($name, $model->getElementName()); }
/** * The actual recursive implementation of getChildBlockNames * * @param Mage_Core_Model_Layout_Element $blockNode * @return array */ protected function _getChildBlockNames($blockNode) { Varien_Profiler::start('turpentine::helper::data::_getChildBlockNames'); if ($blockNode instanceof Mage_Core_Model_Layout_Element) { $blockNames = array((string) $blockNode['name']); foreach ($blockNode->xpath('./block | ./reference') as $childBlockNode) { $blockNames = array_merge($blockNames, $this->_getChildBlockNames($childBlockNode)); } } else { $blockNames = array(); } Varien_Profiler::stop('turpentine::helper::data::_getChildBlockNames'); return $blockNames; }