diff --git a/.rector.php b/.rector.php index cfb35e6e6f5..9b0dfb67431 100644 --- a/.rector.php +++ b/.rector.php @@ -22,6 +22,7 @@ use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector; use Rector\Privatization\Rector as Privatization; use Rector\Renaming\Rector as Renaming; +use Rector\Renaming\ValueObject\MethodCallRename as RenamingMethodCallRename; use Rector\Strict\Rector as Strict; use Rector\Transform\Rector as Transform; use Rector\TypeDeclaration\Rector as TypeDeclaration; @@ -40,6 +41,10 @@ __DIR__, ]) ->withSkipPath(__DIR__ . '/vendor') + # Rename method calls + #->withConfiguredRule(Renaming\MethodCall\RenameMethodRector::class, [ + # new RenamingMethodCallRename('Mage_Core_Model_Layout', 'getBlock', 'getBlockByName'), + #]) ->withRules([ Php85\ArrayDimFetch\ArrayFirstLastRector::class, ]) diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php index d7abdc6a1d2..93eb9105a98 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php @@ -40,7 +40,8 @@ protected function _prepareLayout() { parent::_prepareLayout(); if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { - $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadTinyMce(true); } return $this; diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php index 477acc43716..2b7d0ca94e7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php @@ -23,7 +23,8 @@ protected function _prepareLayout() if ($this->isModuleEnabled('Mage_Cms', 'catalog') && Mage::getSingleton('cms/wysiwyg_config')->isEnabled() ) { - $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadTinyMce(true); } return $this; diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php index 76b7f57e16f..fed6ef20e02 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php @@ -31,7 +31,8 @@ protected function _prepareLayout() { parent::_prepareLayout(); if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { - $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadTinyMce(true); } return $this; diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php index 32d667b4baf..036b241412d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php @@ -21,7 +21,8 @@ protected function _prepareLayout() { parent::_prepareLayout(); if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { - $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadTinyMce(true); } return $this; diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit.php index 83815de9b3a..18c5e4ed66b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit.php @@ -73,7 +73,8 @@ protected function _prepareLayout() { // Load Wysiwyg on demand and Prepare layout if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { - $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadTinyMce(true); } $this->setChild( diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit.php index d8eace9d156..e4220477092 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit.php @@ -37,8 +37,9 @@ public function getModel() protected function _prepareLayout() { // Load Wysiwyg on demand and Prepare layout - if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled() && ($block = $this->getLayout()->getBlock('head'))) { - $block->setCanLoadTinyMce(true); + if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadTinyMce(true); } $this->setChild( diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Head.php b/app/code/core/Mage/Adminhtml/Block/Page/Head.php index 76e4db54b45..46e46f25a92 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Head.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Head.php @@ -11,6 +11,10 @@ * Adminhtml header block * * @package Mage_Adminhtml + * + * @method $this setCanLoadExtJs(bool $value) + * @method $this setCanLoadRulesJs(bool $value) + * @method $this setContainerCssClass(string $value) */ class Mage_Adminhtml_Block_Page_Head extends Mage_Page_Block_Html_Head { diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Menu.php b/app/code/core/Mage/Adminhtml/Block/Page/Menu.php index 2af24bcb432..a2469799b3d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Menu.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Menu.php @@ -12,6 +12,8 @@ * * @package Mage_Adminhtml * + * @method $this setActive(string $menuPath) + * @method string getActive() * @method $this setAdditionalCacheKeyInfo(array $cacheKeyInfo) * @method array getAdditionalCacheKeyInfo() */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php index be575002910..d10006c6204 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php @@ -43,9 +43,8 @@ public function __construct() */ protected function _prepareLayout() { - if ($head = $this->getLayout()->getBlock('head')) { - $head->setCanLoadCalendarJs(true); - } + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadCalendarJs(true); return $this; } diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php index 692c3071e10..1c96895ea49 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php @@ -22,14 +22,12 @@ class Mage_Adminhtml_Block_System_Email_Template_Edit_Form extends Mage_Adminhtm */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $head */ - $head = $this->getLayout()->getBlock('head'); - if ($head) { - $head->addItem('js', 'prototype/window.js') - ->addItem('js_css', 'prototype/windows/themes/default.css') - ->addCss('lib/prototype/windows/themes/magento.css') - ->addItem('js', 'mage/adminhtml/variables.js'); - } + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head + ?->addItem('js', 'prototype/window.js') + ->addItem('js_css', 'prototype/windows/themes/default.css') + ->addCss('lib/prototype/windows/themes/magento.css') + ->addItem('js', 'mage/adminhtml/variables.js'); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget.php b/app/code/core/Mage/Adminhtml/Block/Widget.php index cc6c2b8f88c..b70d5bc48b2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget.php @@ -54,9 +54,8 @@ public function getCurrentUrl($params = []) protected function _addBreadcrumb($label, $title = null, $link = null) { - /** @var Mage_Adminhtml_Block_Widget_Breadcrumbs $block */ - $block = $this->getLayout()->getBlock('breadcrumbs'); - $block->addLink($label, $title, $link); + $block = $this->getLayout()->getBlockAdminhtmlBreadcrumbs(); + $block?->addLink($label, $title, $link); } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php index d1e2b29afd8..c22be4f32d8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php @@ -22,9 +22,8 @@ class Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Date extends Mage_Adminhtml */ protected function _prepareLayout() { - if ($head = $this->getLayout()->getBlock('head')) { - $head->setCanLoadCalendarJs(true); - } + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadCalendarJs(true); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Adminhtml/Controller/Action.php b/app/code/core/Mage/Adminhtml/Controller/Action.php index 3f5db40c84a..7efff05b94c 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Action.php +++ b/app/code/core/Mage/Adminhtml/Controller/Action.php @@ -98,9 +98,11 @@ protected function _getHelper() * * @return $this */ - protected function _setActiveMenu($menuPath) + protected function _setActiveMenu(string $menuPath) { - $this->getLayout()->getBlock('menu')->setActive($menuPath); + $block = $this->getLayout()->getBlockAdminhtmlMenu(); + $block?->setActive($menuPath); + return $this; } @@ -109,9 +111,9 @@ protected function _setActiveMenu($menuPath) */ protected function _addBreadcrumb($label, $title, $link = null) { - /** @var Mage_Adminhtml_Block_Widget_Breadcrumbs $block */ - $block = $this->getLayout()->getBlock('breadcrumbs'); - $block->addLink($label, $title, $link); + $block = $this->getLayout()->getBlockAdminhtmlBreadcrumbs(); + $block?->addLink($label, $title, $link); + return $this; } diff --git a/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php b/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php index 26edc9b1a83..55e6b916841 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php @@ -83,7 +83,8 @@ public function editRoleAction() $this->_addBreadcrumb($breadCrumb, $breadCrumbTitle); - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadExtJs(true); $this->_addLeft( $this->getLayout()->createBlock('adminhtml/api_editroles'), diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php index ba5bd95a916..bb6130f2213 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php @@ -183,8 +183,12 @@ public function editAction() $this->loadLayout(); $this->_setActiveMenu('catalog/categories'); - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true) - ->setContainerCssClass('catalog-categories'); + + $head = $this->getLayout()->getBlockAdminhtmlHead(); + if ($head) { + $head->setCanLoadExtJs(true); + $head->setContainerCssClass('catalog-categories'); + } $this->_addBreadcrumb( Mage::helper('catalog')->__('Manage Catalog Categories'), diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php index 58e9b31a87e..6e875fd3d03 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php @@ -105,7 +105,8 @@ public function newAction() $this->loadLayout(); $this->_setActiveMenu('catalog/reviews_ratings/reviews/all'); - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadExtJs(true); $this->_addContent($this->getLayout()->createBlock('adminhtml/review_add')); $this->_addContent($this->getLayout()->createBlock('adminhtml/review_product_grid')); diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php index 7ef51b73336..2224cacfabb 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php @@ -64,7 +64,9 @@ public function editAction() $this->loadLayout(); $this->_setActiveMenu('catalog/attributes/sets'); - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); + + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadExtJs(true); $this->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog')); $this->_addBreadcrumb( diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php index 6163e8ba447..fa021f7e353 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php @@ -215,7 +215,8 @@ public function newAction() $this->_setActiveMenu('catalog/products'); } - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadExtJs(true); $block = $this->getLayout()->getBlock('catalog.wysiwyg.js'); if ($block) { @@ -268,7 +269,8 @@ public function editAction() ); } - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadExtJs(true); $block = $this->getLayout()->getBlock('catalog.wysiwyg.js'); if ($block) { diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php index 5c07dac983a..b03292972d3 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php @@ -70,7 +70,8 @@ public function editAction() $this->_title($id ? $model->getQueryText() : $this->__('New Search')); - $this->getLayout()->getBlock('head')->setCanLoadRulesJs(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadRulesJs(true); $this->getLayout()->getBlock('catalog_search_edit') ->setData('action', $this->getUrl('*/catalog_search/save')); diff --git a/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php b/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php index 3fb7b0721b1..d83d03c583e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php @@ -109,7 +109,8 @@ public function editRoleAction() $this->_addBreadcrumb($breadCrumb, $breadCrumbTitle); - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadExtJs(true); $this->_addContent( $this->getLayout()->createBlock('adminhtml/permissions_buttons') diff --git a/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php b/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php index 6a5fcb6b619..4a4c6638378 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php @@ -84,9 +84,8 @@ public function editAction() $this->_setActiveMenu('system/config'); - /** @var Mage_Adminhtml_Block_Page_Menu $block */ - $block = $this->getLayout()->getBlock('menu'); - $block->setAdditionalCacheKeyInfo([$current]); + $block = $this->getLayout()->getBlockAdminhtmlMenu(); + $block?->setAdditionalCacheKeyInfo([$current]); $this->_addBreadcrumb( Mage::helper('adminhtml')->__('System'), diff --git a/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php b/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php index 9d1a0557450..4179dcac1be 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php @@ -55,10 +55,12 @@ public function editAction() $this->loadLayout(); $this->_setActiveMenu('system/design'); - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); - $id = (int) $this->getRequest()->getParam('id'); - $design = Mage::getModel('core/design'); + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadExtJs(true); + + $id = (int) $this->getRequest()->getParam('id'); + $design = Mage::getModel('core/design'); if ($id) { $design->load($id); diff --git a/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php b/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php index 86a3605e5c7..15d39a18a80 100644 --- a/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php +++ b/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php @@ -74,7 +74,10 @@ public function editAction() $this->loadLayout(); $this->_setActiveMenu('catalog/urlrewrite'); $this->_addContent($this->getLayout()->createBlock('adminhtml/urlrewrite_edit')); - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); + + $head = $this->getLayout()->getBlockAdminhtmlHead(); + $head?->setCanLoadExtJs(true); + $this->renderLayout(); } diff --git a/app/code/core/Mage/Catalog/Block/Breadcrumbs.php b/app/code/core/Mage/Catalog/Block/Breadcrumbs.php index 7c640db210c..8921d4658ca 100644 --- a/app/code/core/Mage/Catalog/Block/Breadcrumbs.php +++ b/app/code/core/Mage/Catalog/Block/Breadcrumbs.php @@ -33,10 +33,9 @@ public function getTitleSeparator($store = null) */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Breadcrumbs $breadcrumbsBlock */ - $breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs'); - if ($breadcrumbsBlock) { - $breadcrumbsBlock->addCrumb('home', [ + $breadcrumbs = $this->getLayout()->getBlockBreadcrumbs(); + if ($breadcrumbs) { + $breadcrumbs->addCrumb('home', [ 'label' => Mage::helper('catalog')->__('Home'), 'title' => Mage::helper('catalog')->__('Go to Home Page'), 'link' => Mage::getBaseUrl(), @@ -46,13 +45,12 @@ protected function _prepareLayout() $path = Mage::helper('catalog')->getBreadcrumbPath(); foreach ($path as $name => $breadcrumb) { - $breadcrumbsBlock->addCrumb($name, $breadcrumb); + $breadcrumbs->addCrumb($name, $breadcrumb); $title[] = $breadcrumb['label']; } - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle(implode($this->getTitleSeparator(), array_reverse($title))); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle(implode($this->getTitleSeparator(), array_reverse($title))); } return parent::_prepareLayout(); diff --git a/app/code/core/Mage/Catalog/Block/Category/View.php b/app/code/core/Mage/Catalog/Block/Category/View.php index d944dabe63a..830e0a14095 100644 --- a/app/code/core/Mage/Catalog/Block/Category/View.php +++ b/app/code/core/Mage/Catalog/Block/Category/View.php @@ -24,26 +24,25 @@ protected function _prepareLayout() $this->getLayout()->createBlock('catalog/breadcrumbs'); - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { + $head = $this->getLayout()->getBlockHead(); + if ($head) { $category = $this->getCurrentCategory(); if ($title = $category->getMetaTitle()) { - $headBlock->setTitle($title); + $head->setTitle($title); } if ($description = $category->getMetaDescription()) { - $headBlock->setDescription($description); + $head->setDescription($description); } if ($keywords = $category->getMetaKeywords()) { - $headBlock->setKeywords($keywords); + $head->setKeywords($keywords); } /** @var Mage_Catalog_Helper_Category $helper */ $helper = $this->helper('catalog/category'); if ($helper->canUseCanonicalTag()) { - $headBlock->addLinkRel('canonical', $category->getUrl()); + $head->addLinkRel('canonical', $category->getUrl()); } /* @@ -51,7 +50,7 @@ protected function _prepareLayout() */ if ($this->isRssCatalogEnable() && $this->isTopCategory()) { $title = $this->helper('rss')->__('%s RSS Feed', $this->getCurrentCategory()->getName()); - $headBlock->addItem('rss', $this->getRssLink(), 'title="' . $title . '"'); + $head->addItem('rss', $this->getRssLink(), 'title="' . $title . '"'); } } diff --git a/app/code/core/Mage/Catalog/Block/Product/Compare/List.php b/app/code/core/Mage/Catalog/Block/Product/Compare/List.php index a2343cee7c5..71cb0412846 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Compare/List.php +++ b/app/code/core/Mage/Catalog/Block/Product/Compare/List.php @@ -67,10 +67,8 @@ public function getAddToWishlistUrl($product) */ protected function _prepareLayout() { - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle(Mage::helper('catalog')->__('Products Comparison List') . ' - ' . $headBlock->getDefaultTitle()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle(Mage::helper('catalog')->__('Products Comparison List') . ' - ' . $head->getDefaultTitle()); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Catalog/Block/Product/Gallery.php b/app/code/core/Mage/Catalog/Block/Product/Gallery.php index 4da226f9c40..33b0d63849b 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Gallery.php +++ b/app/code/core/Mage/Catalog/Block/Product/Gallery.php @@ -19,9 +19,8 @@ class Mage_Catalog_Block_Product_Gallery extends Mage_Core_Block_Template */ protected function _prepareLayout() { - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle($this->getProduct()->getMetaTitle()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->getProduct()->getMetaTitle()); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Catalog/Block/Product/View.php b/app/code/core/Mage/Catalog/Block/Product/View.php index 3c06951b228..f406c3b6d6e 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View.php +++ b/app/code/core/Mage/Catalog/Block/Product/View.php @@ -37,35 +37,34 @@ protected function _prepareLayout() { $this->getLayout()->createBlock('catalog/breadcrumbs'); - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { + $head = $this->getLayout()->getBlockHead(); + if ($head) { $product = $this->getProduct(); $title = $product->getMetaTitle(); if ($title) { - $headBlock->setTitle($title); + $head->setTitle($title); } $keyword = $product->getMetaKeyword(); $currentCategory = Mage::registry('current_category'); if ($keyword) { - $headBlock->setKeywords($keyword); + $head->setKeywords($keyword); } elseif ($currentCategory) { - $headBlock->setKeywords($product->getName()); + $head->setKeywords($product->getName()); } $description = $product->getMetaDescription(); if ($description) { - $headBlock->setDescription(($description)); + $head->setDescription(($description)); } else { - $headBlock->setDescription(Mage::helper('core/string')->substr($product->getDescription(), 0, 255)); + $head->setDescription(Mage::helper('core/string')->substr($product->getDescription(), 0, 255)); } /** @var Mage_Catalog_Helper_Product $helper */ $helper = $this->helper('catalog/product'); if ($helper->canUseCanonicalTag()) { $params = ['_ignore_category' => true]; - $headBlock->addLinkRel('canonical', $product->getUrlModel()->getUrl($product, $params)); + $head->addLinkRel('canonical', $product->getUrlModel()->getUrl($product, $params)); } } diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php index efaa8c7a191..05cfbb18ece 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php @@ -28,9 +28,8 @@ class Mage_Catalog_Block_Product_View_Options_Type_Date extends Mage_Catalog_Blo */ protected function _prepareLayout() { - if ($head = $this->getLayout()->getBlock('head')) { - $head->setCanLoadCalendarJs(true); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setCanLoadCalendarJs(true); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Catalog/controllers/CategoryController.php b/app/code/core/Mage/Catalog/controllers/CategoryController.php index 4447d9397e7..9023885048a 100644 --- a/app/code/core/Mage/Catalog/controllers/CategoryController.php +++ b/app/code/core/Mage/Catalog/controllers/CategoryController.php @@ -148,12 +148,9 @@ public function viewAction() $this->getLayout()->helper('page/layout')->applyTemplate($settings->getPageLayout()); } - /** @var Mage_Page_Block_Html $root */ - $root = $this->getLayout()->getBlock('root'); - if ($root) { - $root->addBodyClass('categorypath-' . $category->getUrlPath()) - ->addBodyClass('category-' . $category->getUrlKey()); - } + $root = $this->getLayout()->getBlockRoot(); + $root?->addBodyClass('categorypath-' . $category->getUrlPath()) + ->addBodyClass('category-' . $category->getUrlKey()); $this->_initLayoutMessages('catalog/session'); $this->_initLayoutMessages('checkout/session'); diff --git a/app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php b/app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php index c5bf28b9aea..747270efe6c 100644 --- a/app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php +++ b/app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php @@ -19,18 +19,16 @@ class Mage_CatalogSearch_Block_Advanced_Form extends Mage_Core_Block_Template */ public function _prepareLayout() { - // add Home breadcrumb - /** @var Mage_Page_Block_Html_Breadcrumbs $breadcrumbs */ - $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'); - if ($breadcrumbs) { - $breadcrumbs->addCrumb('home', [ + $breadcrumbs = $this->getLayout()->getBlockBreadcrumbs(); + $breadcrumbs + ?->addCrumb('home', [ 'label' => Mage::helper('catalogsearch')->__('Home'), 'title' => Mage::helper('catalogsearch')->__('Go to Home Page'), - 'link' => Mage::getBaseUrl(), - ])->addCrumb('search', [ + 'link' => Mage::getBaseUrl(), + ]) + ->addCrumb('search', [ 'label' => Mage::helper('catalogsearch')->__('Catalog Advanced Search'), ]); - } return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/CatalogSearch/Block/Advanced/Result.php b/app/code/core/Mage/CatalogSearch/Block/Advanced/Result.php index 16ceade47de..84f3a26eb1f 100644 --- a/app/code/core/Mage/CatalogSearch/Block/Advanced/Result.php +++ b/app/code/core/Mage/CatalogSearch/Block/Advanced/Result.php @@ -21,20 +21,20 @@ class Mage_CatalogSearch_Block_Advanced_Result extends Mage_Core_Block_Template */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Breadcrumbs $breadcrumbs */ - $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'); - if ($breadcrumbs) { - $breadcrumbs->addCrumb('home', [ + $breadcrumbs = $this->getLayout()->getBlockBreadcrumbs(); + $breadcrumbs + ?->addCrumb('home', [ 'label' => Mage::helper('catalogsearch')->__('Home'), 'title' => Mage::helper('catalogsearch')->__('Go to Home Page'), - 'link' => Mage::getBaseUrl(), - ])->addCrumb('search', [ + 'link' => Mage::getBaseUrl(), + ]) + ->addCrumb('search', [ 'label' => Mage::helper('catalogsearch')->__('Catalog Advanced Search'), - 'link' => $this->getUrl('*/*/'), - ])->addCrumb('search_result', [ + 'link' => $this->getUrl('*/*/'), + ]) + ->addCrumb('search_result', [ 'label' => Mage::helper('catalogsearch')->__('Results'), ]); - } return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/CatalogSearch/Block/Result.php b/app/code/core/Mage/CatalogSearch/Block/Result.php index 08481135ec0..8c666328af7 100644 --- a/app/code/core/Mage/CatalogSearch/Block/Result.php +++ b/app/code/core/Mage/CatalogSearch/Block/Result.php @@ -46,25 +46,27 @@ protected function _prepareLayout() /** @var Mage_CatalogSearch_Helper_Data $helper */ $helper = $this->helper('catalogsearch'); - // add Home breadcrumb - /** @var Mage_Page_Block_Html_Breadcrumbs $breadcrumbs */ - $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'); + $breadcrumbs = $this->getLayout()->getBlockBreadcrumbs(); if ($breadcrumbs) { $title = $this->__("Search results for: '%s'", $helper->getQueryText()); - $breadcrumbs->addCrumb('home', [ - 'label' => $this->__('Home'), - 'title' => $this->__('Go to Home Page'), - 'link' => Mage::getBaseUrl(), - ])->addCrumb('search', [ - 'label' => $title, - 'title' => $title, - ]); + $breadcrumbs + ->addCrumb('home', [ + 'label' => $this->__('Home'), + 'title' => $this->__('Go to Home Page'), + 'link' => Mage::getBaseUrl(), + ]) + ->addCrumb('search', [ + 'label' => $title, + 'title' => $title, + ]); } // modify page title $title = $this->__("Search results for: '%s'", $helper->getEscapedQueryText()); - $this->getLayout()->getBlock('head')->setTitle($title); + + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($title); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Address/Select.php b/app/code/core/Mage/Checkout/Block/Multishipping/Address/Select.php index 001e60b5545..08926a12b59 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Address/Select.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Address/Select.php @@ -19,9 +19,8 @@ class Mage_Checkout_Block_Multishipping_Address_Select extends Mage_Checkout_Blo */ protected function _prepareLayout() { - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle(Mage::helper('checkout')->__('Change Billing Address') . ' - ' . $headBlock->getDefaultTitle()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle(Mage::helper('checkout')->__('Change Billing Address') . ' - ' . $head->getDefaultTitle()); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Addresses.php b/app/code/core/Mage/Checkout/Block/Multishipping/Addresses.php index 2eefc5c997e..cb7a5b6959b 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Addresses.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Addresses.php @@ -29,9 +29,8 @@ public function getCheckout() */ protected function _prepareLayout() { - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle(Mage::helper('checkout')->__('Ship to Multiple Addresses') . ' - ' . $headBlock->getDefaultTitle()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle(Mage::helper('checkout')->__('Ship to Multiple Addresses') . ' - ' . $head->getDefaultTitle()); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php b/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php index 7f369ae3ebd..c3a79e98bbe 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php @@ -19,11 +19,10 @@ class Mage_Checkout_Block_Multishipping_Billing extends Mage_Payment_Block_Form_ */ protected function _prepareLayout() { - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle( - Mage::helper('checkout')->__('Billing Information - %s', $headBlock->getDefaultTitle()), - ); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle( + Mage::helper('checkout')->__('Billing Information - %s', $head->getDefaultTitle()), + ); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Overview.php b/app/code/core/Mage/Checkout/Block/Multishipping/Overview.php index 77b6abd07c8..3eab4d85456 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Overview.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Overview.php @@ -42,11 +42,10 @@ public function getCheckout() */ protected function _prepareLayout() { - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle( - $this->__('Review Order - %s', $headBlock->getDefaultTitle()), - ); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle( + $this->__('Review Order - %s', $head->getDefaultTitle()), + ); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Shipping.php b/app/code/core/Mage/Checkout/Block/Multishipping/Shipping.php index d107611ecf9..0f2c899739d 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Shipping.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Shipping.php @@ -29,9 +29,8 @@ public function getCheckout() */ protected function _prepareLayout() { - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle(Mage::helper('checkout')->__('Shipping Methods') . ' - ' . $headBlock->getDefaultTitle()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle(Mage::helper('checkout')->__('Shipping Methods') . ' - ' . $head->getDefaultTitle()); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php b/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php index 26913a46a20..d910432ba55 100644 --- a/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php +++ b/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php @@ -47,9 +47,8 @@ public function newShippingAction() ->setSuccessUrl(Mage::getUrl('*/*/shippingSaved')) ->setErrorUrl(Mage::getUrl('*/*/*')); - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle($addressForm->getTitle() . ' - ' . $headBlock->getDefaultTitle()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($addressForm->getTitle() . ' - ' . $head->getDefaultTitle()); if ($this->_getCheckout()->getCustomerDefaultShippingAddress()) { $addressForm->setBackUrl(Mage::getUrl('*/multishipping/addresses')); @@ -83,9 +82,8 @@ public function editShippingAction() ->setSuccessUrl(Mage::getUrl('*/*/editShippingPost', ['id' => $this->getRequest()->getParam('id')])) ->setErrorUrl(Mage::getUrl('*/*/*')); - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle($addressForm->getTitle() . ' - ' . $headBlock->getDefaultTitle()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($addressForm->getTitle() . ' - ' . $head->getDefaultTitle()); if ($this->_getCheckout()->getCustomerDefaultShippingAddress()) { $addressForm->setBackUrl(Mage::getUrl('*/multishipping/shipping')); @@ -124,9 +122,8 @@ public function newBillingAction() ->setErrorUrl(Mage::getUrl('*/*/*')) ->setBackUrl(Mage::getUrl('*/*/selectBilling')); - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle($addressForm->getTitle() . ' - ' . $headBlock->getDefaultTitle()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($addressForm->getTitle() . ' - ' . $head->getDefaultTitle()); } $this->renderLayout(); @@ -142,9 +139,8 @@ public function editAddressAction() ->setErrorUrl(Mage::getUrl('*/*/*', ['id' => $this->getRequest()->getParam('id')])) ->setBackUrl(Mage::getUrl('*/*/selectBilling')); - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle($addressForm->getTitle() . ' - ' . $headBlock->getDefaultTitle()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($addressForm->getTitle() . ' - ' . $head->getDefaultTitle()); } $this->renderLayout(); @@ -162,9 +158,9 @@ public function editBillingAction() ->setSuccessUrl(Mage::getUrl('*/*/saveBilling', ['id' => $this->getRequest()->getParam('id')])) ->setErrorUrl(Mage::getUrl('*/*/*', ['id' => $this->getRequest()->getParam('id')])) ->setBackUrl(Mage::getUrl('*/multishipping/overview')); - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle($addressForm->getTitle() . ' - ' . $headBlock->getDefaultTitle()); - } + + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($addressForm->getTitle() . ' - ' . $head->getDefaultTitle()); } $this->renderLayout(); diff --git a/app/code/core/Mage/Checkout/controllers/OnepageController.php b/app/code/core/Mage/Checkout/controllers/OnepageController.php index c678ea188fc..5954cbee670 100644 --- a/app/code/core/Mage/Checkout/controllers/OnepageController.php +++ b/app/code/core/Mage/Checkout/controllers/OnepageController.php @@ -157,7 +157,12 @@ protected function _getAdditionalHtml() */ protected function _getReviewHtml() { - return $this->getLayout()->getBlock('root')->toHtml(); + $root = $this->getLayout()->getBlockRoot(); + if ($root) { + return $root->toHtml(); + } + + return ''; } /** @@ -202,7 +207,10 @@ public function indexAction() $this->getOnepage()->initCheckout(); $this->loadLayout(); $this->_initLayoutMessages('customer/session'); - $this->getLayout()->getBlock('head')->setTitle($this->__('Checkout')); + + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Checkout')); + $this->renderLayout(); } diff --git a/app/code/core/Mage/Cms/Block/Page.php b/app/code/core/Mage/Cms/Block/Page.php index e9562b3f671..01e75dd3048 100644 --- a/app/code/core/Mage/Cms/Block/Page.php +++ b/app/code/core/Mage/Cms/Block/Page.php @@ -48,11 +48,10 @@ protected function _prepareLayout() { $page = $this->getPage(); $breadcrumbsArray = []; - $breadcrumbs = null; // show breadcrumbs if (Mage::getStoreConfig('web/default/show_cms_breadcrumbs') - && ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) + && ($breadcrumbs = $this->getLayout()->getBlockBreadcrumbs()) && ($page->getIdentifier() !== Mage::getStoreConfig('web/default/cms_home_page')) && ($page->getIdentifier() !== Mage::getStoreConfig('web/default/cms_no_route')) ) { @@ -83,14 +82,10 @@ protected function _prepareLayout() } } - /** @var Mage_Page_Block_Html $root */ - $root = $this->getLayout()->getBlock('root'); - if ($root) { - $root->addBodyClass('cms-' . $page->getIdentifier()); - } + $root = $this->getLayout()->getBlockRoot(); + $root?->addBodyClass('cms-' . $page->getIdentifier()); - /** @var Mage_Page_Block_Html_Head $head */ - $head = $this->getLayout()->getBlock('head'); + $head = $this->getLayout()->getBlockHead(); if ($head) { $head->setTitle($page->getTitle()); $head->setKeywords($page->getMetaKeywords()); diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php index 86a6e63e59a..b115801a865 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Action.php +++ b/app/code/core/Mage/Core/Controller/Varien/Action.php @@ -979,16 +979,16 @@ protected function _title($text = null, $resetIfExists = true) protected function _renderTitles() { if ($this->_isLayoutLoaded && $this->_titles) { - $titleBlock = $this->getLayout()->getBlock('head'); - if ($titleBlock) { + $head = $this->getLayout()->getBlockHead(); + if ($head) { if (!$this->_removeDefaultTitle) { - $title = trim($titleBlock->getTitle()); + $title = trim($head->getTitle()); if ($title) { array_unshift($this->_titles, $title); } } - $titleBlock->setTitle(implode(' / ', array_reverse($this->_titles))); + $head->setTitle(implode(' / ', array_reverse($this->_titles))); } } } diff --git a/app/code/core/Mage/Core/Model/Layout.php b/app/code/core/Mage/Core/Model/Layout.php index 009d8275d4e..83ea9931fff 100644 --- a/app/code/core/Mage/Core/Model/Layout.php +++ b/app/code/core/Mage/Core/Model/Layout.php @@ -14,6 +14,9 @@ */ class Mage_Core_Model_Layout extends Varien_Simplexml_Config { + use Mage_Core_Model_Layout_Traits_Adminhtml; + use Mage_Core_Model_Layout_Traits_Frontend; + /** * Layout Update module * @@ -540,6 +543,8 @@ public function getAllBlocks() * Get block object by name * * @param string $name + * @deprecated Use getBlockByName() which returns null if block does not exist + * @see getBlockByName() * @return false|Mage_Core_Block_Abstract */ public function getBlock($name) @@ -547,6 +552,19 @@ public function getBlock($name) return $this->_blocks[$name] ?? false; } + /** + * Returns null instead of false if block does not exist + */ + public function getBlockByName(string $name): ?Mage_Core_Block_Abstract + { + $block = $this->_blocks[$name] ?? null; + if (!$block instanceof Mage_Core_Block_Abstract) { + return null; + } + + return $block; + } + /** * Add a block to output * diff --git a/app/code/core/Mage/Core/Model/Layout/Traits/Adminhtml.php b/app/code/core/Mage/Core/Model/Layout/Traits/Adminhtml.php new file mode 100644 index 00000000000..0a602b60831 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Layout/Traits/Adminhtml.php @@ -0,0 +1,48 @@ +getBlockByName('breadcrumbs'); + if (!$block instanceof Mage_Adminhtml_Block_Widget_Breadcrumbs) { + return null; + } + + return $block; + } + + public function getBlockAdminhtmlHead(): ?Mage_Adminhtml_Block_Page_Head + { + $block = $this->getBlockByName('head'); + if (!$block instanceof Mage_Adminhtml_Block_Page_Head) { + return null; + } + + return $block; + } + + public function getBlockAdminhtmlMenu(): ?Mage_Adminhtml_Block_Page_Menu + { + $block = $this->getBlockByName('menu'); + if (!$block instanceof Mage_Adminhtml_Block_Page_Menu) { + return null; + } + + return $block; + } +} diff --git a/app/code/core/Mage/Core/Model/Layout/Traits/Frontend.php b/app/code/core/Mage/Core/Model/Layout/Traits/Frontend.php new file mode 100644 index 00000000000..c4ff68a0bfe --- /dev/null +++ b/app/code/core/Mage/Core/Model/Layout/Traits/Frontend.php @@ -0,0 +1,48 @@ +getBlockByName('breadcrumbs'); + if (!$block instanceof Mage_Page_Block_Html_Breadcrumbs) { + return null; + } + + return $block; + } + + public function getBlockHead(): ?Mage_Page_Block_Html_Head + { + $block = $this->getBlockByName('head'); + if (!$block instanceof Mage_Page_Block_Html_Head) { + return null; + } + + return $block; + } + + public function getBlockRoot(): ?Mage_Page_Block_Html + { + $block = $this->getBlockByName('root'); + if (!$block instanceof Mage_Page_Block_Html) { + return null; + } + + return $block; + } +} diff --git a/app/code/core/Mage/Customer/Block/Address/Book.php b/app/code/core/Mage/Customer/Block/Address/Book.php index d71adcdf9fd..bad887fb487 100644 --- a/app/code/core/Mage/Customer/Block/Address/Book.php +++ b/app/code/core/Mage/Customer/Block/Address/Book.php @@ -22,8 +22,8 @@ class Mage_Customer_Block_Address_Book extends Mage_Core_Block_Template */ protected function _prepareLayout() { - $this->getLayout()->getBlock('head') - ->setTitle(Mage::helper('customer')->__('Address Book')); + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle(Mage::helper('customer')->__('Address Book')); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Customer/Block/Address/Edit.php b/app/code/core/Mage/Customer/Block/Address/Edit.php index b4e1a97ac87..e595163e8a7 100644 --- a/app/code/core/Mage/Customer/Block/Address/Edit.php +++ b/app/code/core/Mage/Customer/Block/Address/Edit.php @@ -49,9 +49,8 @@ protected function _prepareLayout() ->setSuffix($this->getCustomer()->getSuffix()); } - if ($headBlock = $this->getLayout()->getBlock('head')) { - $headBlock->setTitle($this->getTitle()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->getTitle()); if ($postedData = Mage::getSingleton('customer/session')->getAddressFormData(true)) { $this->_address->addData($postedData); diff --git a/app/code/core/Mage/Customer/Block/Form/Register.php b/app/code/core/Mage/Customer/Block/Form/Register.php index 9c86317aa57..edf2d93f7a7 100644 --- a/app/code/core/Mage/Customer/Block/Form/Register.php +++ b/app/code/core/Mage/Customer/Block/Form/Register.php @@ -31,7 +31,9 @@ class Mage_Customer_Block_Form_Register extends Mage_Directory_Block_Data */ protected function _prepareLayout() { - $this->getLayout()->getBlock('head')->setTitle(Mage::helper('customer')->__('Create New Customer Account')); + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle(Mage::helper('customer')->__('Create New Customer Account')); + return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Customer/controllers/AccountController.php b/app/code/core/Mage/Customer/controllers/AccountController.php index 30ec58523a2..2dcbfefd6c7 100644 --- a/app/code/core/Mage/Customer/controllers/AccountController.php +++ b/app/code/core/Mage/Customer/controllers/AccountController.php @@ -102,7 +102,10 @@ public function indexAction() $this->getLayout()->getBlock('content')->append( $this->getLayout()->createBlock('customer/account_dashboard'), ); - $this->getLayout()->getBlock('head')->setTitle($this->__('My Account')); + + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('My Account')); + $this->renderLayout(); } @@ -120,7 +123,10 @@ public function loginAction() $this->loadLayout(); $this->_initLayoutMessages('customer/session'); $this->_initLayoutMessages('catalog/session'); - $this->getLayout()->getBlock('head')->setTitle($this->__('Customer Login')); + + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Customer Login')); + $this->renderLayout(); } @@ -974,7 +980,9 @@ public function editAction() $customer->setChangePassword(1); } - $this->getLayout()->getBlock('head')->setTitle($this->__('Account Information')); + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Account Information')); + $this->getLayout()->getBlock('messages')->setEscapeMessageFlag(true); $this->renderLayout(); } diff --git a/app/code/core/Mage/Downloadable/controllers/CustomerController.php b/app/code/core/Mage/Downloadable/controllers/CustomerController.php index 2cac2326938..135eb4fe22e 100644 --- a/app/code/core/Mage/Downloadable/controllers/CustomerController.php +++ b/app/code/core/Mage/Downloadable/controllers/CustomerController.php @@ -41,10 +41,8 @@ public function productsAction() $block->setRefererUrl($this->_getRefererUrl()); } - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle(Mage::helper('downloadable')->__('My Downloadable Products')); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle(Mage::helper('downloadable')->__('My Downloadable Products')); $this->renderLayout(); } diff --git a/app/code/core/Mage/Newsletter/controllers/ManageController.php b/app/code/core/Mage/Newsletter/controllers/ManageController.php index c470c40d6e6..ea90b9b7734 100644 --- a/app/code/core/Mage/Newsletter/controllers/ManageController.php +++ b/app/code/core/Mage/Newsletter/controllers/ManageController.php @@ -39,7 +39,9 @@ public function indexAction() $block->setRefererUrl($this->_getRefererUrl()); } - $this->getLayout()->getBlock('head')->setTitle($this->__('Newsletter Subscription')); + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Newsletter Subscription')); + $this->renderLayout(); } diff --git a/app/code/core/Mage/Page/Helper/Layout.php b/app/code/core/Mage/Page/Helper/Layout.php index 08bec8fa600..af3eaf24079 100644 --- a/app/code/core/Mage/Page/Helper/Layout.php +++ b/app/code/core/Mage/Page/Helper/Layout.php @@ -56,13 +56,10 @@ public function applyTemplate($pageLayout = null) return $this; } - if ($this->getLayout()->getBlock('root') - && !$this->getLayout()->getBlock('root')->getIsHandle() - ) { + $root = $this->getLayout()->getBlockRoot(); + if ($root && !$root->getIsHandle()) { // If not applied handle - $this->getLayout() - ->getBlock('root') - ->setTemplate($pageLayout->getTemplate()); + $root->setTemplate($pageLayout->getTemplate()); } return $this; @@ -75,10 +72,9 @@ public function applyTemplate($pageLayout = null) */ public function getCurrentPageLayout() { - if ($this->getLayout()->getBlock('root') - && $this->getLayout()->getBlock('root')->getLayoutCode() - ) { - return $this->_getConfig()->getPageLayout($this->getLayout()->getBlock('root')->getLayoutCode()); + $root = $this->getLayout()->getBlockRoot(); + if ($root && $root->getLayoutCode()) { + return $this->_getConfig()->getPageLayout($root->getLayoutCode()); } // All loaded handles diff --git a/app/code/core/Mage/Paypal/Controller/Express/Abstract.php b/app/code/core/Mage/Paypal/Controller/Express/Abstract.php index 753e406bd63..4e471c54a90 100644 --- a/app/code/core/Mage/Paypal/Controller/Express/Abstract.php +++ b/app/code/core/Mage/Paypal/Controller/Express/Abstract.php @@ -264,9 +264,12 @@ public function saveShippingMethodAction() $this->_checkout->updateShippingMethod($this->getRequest()->getParam('shipping_method')); if ($isAjax) { $this->loadLayout('paypal_express_review_details'); - $this->getResponse()->setBody($this->getLayout()->getBlock('root') - ->setQuote($this->_getQuote()) - ->toHtml()); + + $root = $this->getLayout()->getBlockRoot(); + if ($root) { + $this->getResponse()->setBody($root->setQuote($this->_getQuote())->toHtml()); + } + return; } } catch (Mage_Core_Exception $e) { diff --git a/app/code/core/Mage/Review/controllers/CustomerController.php b/app/code/core/Mage/Review/controllers/CustomerController.php index dbdb6f184d9..9b79b7cfa91 100644 --- a/app/code/core/Mage/Review/controllers/CustomerController.php +++ b/app/code/core/Mage/Review/controllers/CustomerController.php @@ -64,7 +64,8 @@ public function indexAction() $block->setRefererUrl($this->_getRefererUrl()); } - $this->getLayout()->getBlock('head')->setTitle($this->__('My Product Reviews')); + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('My Product Reviews')); $this->renderLayout(); } @@ -82,7 +83,9 @@ public function viewAction() $navigationBlock->setActive('review/customer'); } - $this->getLayout()->getBlock('head')->setTitle($this->__('Review Details')); + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Review Details')); + $this->renderLayout(); } } diff --git a/app/code/core/Mage/Review/controllers/ProductController.php b/app/code/core/Mage/Review/controllers/ProductController.php index 47387cb3d4b..af0ecdb09e2 100644 --- a/app/code/core/Mage/Review/controllers/ProductController.php +++ b/app/code/core/Mage/Review/controllers/ProductController.php @@ -221,17 +221,16 @@ public function listAction() $this->_initProductLayout($product); - // update breadcrumbs - /** @var Mage_Page_Block_Html_Breadcrumbs $breadcrumbsBlock */ - $breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs'); - if ($breadcrumbsBlock) { - $breadcrumbsBlock->addCrumb('product', [ - 'label' => $product->getName(), - 'link' => $product->getProductUrl(), - 'readonly' => true, + $breadcrumbs = $this->getLayout()->getBlockBreadcrumbs(); + $breadcrumbs + ?->addCrumb('product', [ + 'label' => $product->getName(), + 'link' => $product->getProductUrl(), + 'readonly' => true, + ]) + ->addCrumb('reviews', [ + 'label' => Mage::helper('review')->__('Product Reviews'), ]); - $breadcrumbsBlock->addCrumb('reviews', ['label' => Mage::helper('review')->__('Product Reviews')]); - } $this->renderLayout(); } elseif (!$this->getResponse()->isRedirect()) { diff --git a/app/code/core/Mage/Rss/Block/List.php b/app/code/core/Mage/Rss/Block/List.php index d77f92a999c..50e11881ea1 100644 --- a/app/code/core/Mage/Rss/Block/List.php +++ b/app/code/core/Mage/Rss/Block/List.php @@ -26,12 +26,13 @@ class Mage_Rss_Block_List extends Mage_Core_Block_Template */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $head */ - $head = $this->getLayout()->getBlock('head'); - $feeds = $this->getRssMiscFeeds(); - if ($head && !empty($feeds)) { - foreach ($feeds as $feed) { - $head->addItem('rss', $feed['url'], 'title="' . $feed['label'] . '"'); + $head = $this->getLayout()->getBlockHead(); + if ($head) { + $feeds = $this->getRssMiscFeeds(); + if (!empty($feeds)) { + foreach ($feeds as $feed) { + $head->addItem('rss', $feed['url'], 'title="' . $feed['label'] . '"'); + } } } diff --git a/app/code/core/Mage/Sales/Block/Order/Creditmemo.php b/app/code/core/Mage/Sales/Block/Order/Creditmemo.php index 4dfc7722afe..96aef85f9ec 100644 --- a/app/code/core/Mage/Sales/Block/Order/Creditmemo.php +++ b/app/code/core/Mage/Sales/Block/Order/Creditmemo.php @@ -25,11 +25,8 @@ protected function _construct() */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); /** @var Mage_Payment_Helper_Data $helper */ $helper = $this->helper('payment'); diff --git a/app/code/core/Mage/Sales/Block/Order/Info.php b/app/code/core/Mage/Sales/Block/Order/Info.php index 0e41f3c0819..3ec418c8988 100644 --- a/app/code/core/Mage/Sales/Block/Order/Info.php +++ b/app/code/core/Mage/Sales/Block/Order/Info.php @@ -27,11 +27,8 @@ protected function _construct() */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); /** @var Mage_Payment_Helper_Data $helper */ $helper = $this->helper('payment'); diff --git a/app/code/core/Mage/Sales/Block/Order/Invoice.php b/app/code/core/Mage/Sales/Block/Order/Invoice.php index 23cb0629619..0c1e4066e37 100644 --- a/app/code/core/Mage/Sales/Block/Order/Invoice.php +++ b/app/code/core/Mage/Sales/Block/Order/Invoice.php @@ -25,11 +25,8 @@ protected function _construct() */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); /** @var Mage_Payment_Helper_Data $helper */ $helper = $this->helper('payment'); diff --git a/app/code/core/Mage/Sales/Block/Order/Print.php b/app/code/core/Mage/Sales/Block/Order/Print.php index 9569cca8164..183ab8c8d8f 100644 --- a/app/code/core/Mage/Sales/Block/Order/Print.php +++ b/app/code/core/Mage/Sales/Block/Order/Print.php @@ -19,11 +19,8 @@ class Mage_Sales_Block_Order_Print extends Mage_Sales_Block_Items_Abstract */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('Print Order # %s', $this->getOrder()->getRealOrderId())); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Print Order # %s', $this->getOrder()->getRealOrderId())); /** @var Mage_Payment_Helper_Data $helper */ $helper = $this->helper('payment'); diff --git a/app/code/core/Mage/Sales/Block/Order/Print/Creditmemo.php b/app/code/core/Mage/Sales/Block/Order/Print/Creditmemo.php index 3dbf346bc48..4e2b9b3fcac 100644 --- a/app/code/core/Mage/Sales/Block/Order/Print/Creditmemo.php +++ b/app/code/core/Mage/Sales/Block/Order/Print/Creditmemo.php @@ -19,11 +19,8 @@ class Mage_Sales_Block_Order_Print_Creditmemo extends Mage_Sales_Block_Items_Abs */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); /** @var Mage_Payment_Helper_Data $helper */ $helper = $this->helper('payment'); diff --git a/app/code/core/Mage/Sales/Block/Order/Print/Invoice.php b/app/code/core/Mage/Sales/Block/Order/Print/Invoice.php index 5a732ed677a..e4743baf580 100644 --- a/app/code/core/Mage/Sales/Block/Order/Print/Invoice.php +++ b/app/code/core/Mage/Sales/Block/Order/Print/Invoice.php @@ -19,11 +19,8 @@ class Mage_Sales_Block_Order_Print_Invoice extends Mage_Sales_Block_Items_Abstra */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); /** @var Mage_Payment_Helper_Data $helper */ $helper = $this->helper('payment'); diff --git a/app/code/core/Mage/Sales/Block/Order/Print/Shipment.php b/app/code/core/Mage/Sales/Block/Order/Print/Shipment.php index b6375510b27..9bfbb37b81b 100644 --- a/app/code/core/Mage/Sales/Block/Order/Print/Shipment.php +++ b/app/code/core/Mage/Sales/Block/Order/Print/Shipment.php @@ -57,11 +57,8 @@ protected function _beforeToHtml() */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); /** @var Mage_Payment_Helper_Data $helper */ $helper = $this->helper('payment'); diff --git a/app/code/core/Mage/Sales/Block/Order/Shipment.php b/app/code/core/Mage/Sales/Block/Order/Shipment.php index a617f67231d..92c4a190f1a 100644 --- a/app/code/core/Mage/Sales/Block/Order/Shipment.php +++ b/app/code/core/Mage/Sales/Block/Order/Shipment.php @@ -25,11 +25,8 @@ protected function _construct() */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); /** @var Mage_Payment_Helper_Data $helper */ $helper = $this->helper('payment'); diff --git a/app/code/core/Mage/Sales/Block/Order/View.php b/app/code/core/Mage/Sales/Block/Order/View.php index 7d5d2a9ed5c..976a6b985a6 100644 --- a/app/code/core/Mage/Sales/Block/Order/View.php +++ b/app/code/core/Mage/Sales/Block/Order/View.php @@ -25,11 +25,8 @@ protected function _construct() */ protected function _prepareLayout() { - /** @var Mage_Page_Block_Html_Head $headBlock */ - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId())); /** @var Mage_Payment_Helper_Data $helper */ $helper = $this->helper('payment'); diff --git a/app/code/core/Mage/Sales/Helper/Guest.php b/app/code/core/Mage/Sales/Helper/Guest.php index db8ee1fb7c6..52f81454dba 100644 --- a/app/code/core/Mage/Sales/Helper/Guest.php +++ b/app/code/core/Mage/Sales/Helper/Guest.php @@ -124,23 +124,24 @@ public function loadValidOrder() */ public function getBreadcrumbs($controller) { - /** @var Mage_Page_Block_Html_Breadcrumbs $breadcrumbs */ - $breadcrumbs = $controller->getLayout()->getBlock('breadcrumbs'); - $breadcrumbs->addCrumb( - 'home', - [ - 'label' => $this->__('Home'), - 'title' => $this->__('Go to Home Page'), - 'link' => Mage::getBaseUrl(), - ], - ); - $breadcrumbs->addCrumb( - 'cms_page', - [ - 'label' => $this->__('Order Information'), - 'title' => $this->__('Order Information'), - ], - ); + $breadcrumbs = $controller->getLayout()->getBlockBreadcrumbs(); + if ($breadcrumbs) { + $breadcrumbs->addCrumb( + 'home', + [ + 'label' => $this->__('Home'), + 'title' => $this->__('Go to Home Page'), + 'link' => Mage::getBaseUrl(), + ], + ); + $breadcrumbs->addCrumb( + 'cms_page', + [ + 'label' => $this->__('Order Information'), + 'title' => $this->__('Order Information'), + ], + ); + } } /** diff --git a/app/code/core/Mage/Sales/controllers/OrderController.php b/app/code/core/Mage/Sales/controllers/OrderController.php index 7ef19db57cc..9446aaf9725 100644 --- a/app/code/core/Mage/Sales/controllers/OrderController.php +++ b/app/code/core/Mage/Sales/controllers/OrderController.php @@ -40,7 +40,8 @@ public function historyAction() $this->loadLayout(); $this->_initLayoutMessages('catalog/session'); - $this->getLayout()->getBlock('head')->setTitle($this->__('My Orders')); + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('My Orders')); if ($block = $this->getLayout()->getBlock('customer.account.link.back')) { $block->setRefererUrl($this->_getRefererUrl()); diff --git a/app/code/core/Mage/Tag/Block/Product/Result.php b/app/code/core/Mage/Tag/Block/Product/Result.php index 3de96b43445..154ba75fe17 100644 --- a/app/code/core/Mage/Tag/Block/Product/Result.php +++ b/app/code/core/Mage/Tag/Block/Product/Result.php @@ -35,8 +35,13 @@ public function getTag() protected function _prepareLayout() { $title = $this->getHeaderText(); - $this->getLayout()->getBlock('head')->setTitle($title); - $this->getLayout()->getBlock('root')->setHeaderTitle($title); + + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($title); + + $root = $this->getLayout()->getBlockRoot(); + $root?->setHeaderTitle($title); + return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Tag/controllers/CustomerController.php b/app/code/core/Mage/Tag/controllers/CustomerController.php index 6dccdb2af1e..e4b90377769 100644 --- a/app/code/core/Mage/Tag/controllers/CustomerController.php +++ b/app/code/core/Mage/Tag/controllers/CustomerController.php @@ -53,7 +53,8 @@ public function indexAction() $block->setRefererUrl($this->_getRefererUrl()); } - $this->getLayout()->getBlock('head')->setTitle(Mage::helper('tag')->__('My Tags')); + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle(Mage::helper('tag')->__('My Tags')); $this->renderLayout(); } @@ -76,7 +77,9 @@ public function viewAction() } $this->_initLayoutMessages('checkout/session'); - $this->getLayout()->getBlock('head')->setTitle(Mage::helper('tag')->__('My Tags')); + + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle(Mage::helper('tag')->__('My Tags')); $this->renderLayout(); } else { $this->_forward('noRoute'); diff --git a/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php b/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php index 419829ec571..2a182d31d45 100644 --- a/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php +++ b/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php @@ -28,10 +28,8 @@ class Mage_Wishlist_Block_Customer_Sharing extends Mage_Core_Block_Template */ protected function _prepareLayout() { - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('Wishlist Sharing')); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('Wishlist Sharing')); return $this; } diff --git a/app/code/core/Mage/Wishlist/Block/Customer/Wishlist.php b/app/code/core/Mage/Wishlist/Block/Customer/Wishlist.php index 751556c4de4..0ca03e8eb06 100644 --- a/app/code/core/Mage/Wishlist/Block/Customer/Wishlist.php +++ b/app/code/core/Mage/Wishlist/Block/Customer/Wishlist.php @@ -39,10 +39,9 @@ protected function _prepareCollection($collection) protected function _prepareLayout() { parent::_prepareLayout(); - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->__('My Wishlist')); - } + + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->__('My Wishlist')); return $this; } diff --git a/app/code/core/Mage/Wishlist/Block/Share/Wishlist.php b/app/code/core/Mage/Wishlist/Block/Share/Wishlist.php index 5d1a7ab4f28..b59859956e2 100644 --- a/app/code/core/Mage/Wishlist/Block/Share/Wishlist.php +++ b/app/code/core/Mage/Wishlist/Block/Share/Wishlist.php @@ -30,10 +30,8 @@ protected function _prepareLayout() { parent::_prepareLayout(); - $headBlock = $this->getLayout()->getBlock('head'); - if ($headBlock) { - $headBlock->setTitle($this->getHeader()); - } + $head = $this->getLayout()->getBlockHead(); + $head?->setTitle($this->getHeader()); return $this; }