/** * Set child block * * @param string $alias * @param Mage_Core_Block_Abstract|string $block * @return Mage_Core_Block_Abstract */ public function setChild($alias, $block) { $layout = $this->getLayout(); if (!$layout) { return $this; } $thisName = $this->getNameInLayout(); if ($layout->getChildName($thisName, $alias)) { $this->unsetChild($alias); } if ($block instanceof self) { if ($block->getIsAnonymous()) { $block->setNameInLayout($this->getNameInLayout() . '.' . $alias); } $block = $block->getNameInLayout(); } $layout->setChild($thisName, $block, $alias); return $this; }
/** * Insert child block * * @param Mage_Core_Block_Abstract $block * @param string $siblingName * @param boolean $after * @param string $alias * @return object $this */ public function insert($block, $siblingName = '', $after = false, $alias = '') { if ($block->getIsAnonymous()) { $this->setChild('', $block); $name = $block->getNameInLayout(); } elseif ('' != $alias) { $this->setChild($alias, $block); $name = $block->getNameInLayout(); } else { $name = $block->getNameInLayout(); $this->setChild($name, $block); } if ('' === $siblingName) { if ($after) { array_push($this->_sortedChildren, $name); } else { array_unshift($this->_sortedChildren, $name); } } else { $key = array_search($siblingName, $this->_sortedChildren); if (false !== $key) { if ($after) { $key++; } array_splice($this->_sortedChildren, $key, 0, $name); } else { if ($after) { array_push($this->_sortedChildren, $name); } else { array_unshift($this->_sortedChildren, $name); } } } return $this; }
public function testSetGetIsAnonymous() { $this->assertFalse($this->_block->getIsAnonymous()); $this->_block->setIsAnonymous(true); $this->assertTrue($this->_block->getIsAnonymous()); }