Page.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Model\View\Result;
  7. use Magento\Framework\Translate;
  8. use Magento\Framework\View;
  9. /**
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Page extends View\Result\Page
  14. {
  15. /**
  16. * Define active menu item in menu block
  17. *
  18. * @param string $itemId current active menu item
  19. * @return $this
  20. */
  21. public function setActiveMenu($itemId)
  22. {
  23. /** @var $menuBlock \Magento\Backend\Block\Menu */
  24. $menuBlock = $this->layout->getBlock('menu');
  25. $menuBlock->setActive($itemId);
  26. $parents = $menuBlock->getMenuModel()->getParentItems($itemId);
  27. foreach ($parents as $item) {
  28. /** @var $item \Magento\Backend\Model\Menu\Item */
  29. $this->getConfig()->getTitle()->prepend($item->getTitle());
  30. }
  31. return $this;
  32. }
  33. /**
  34. * Add link to breadcrumb block
  35. *
  36. * @param string $label
  37. * @param string $title
  38. * @param string|null $link
  39. * @return $this
  40. */
  41. public function addBreadcrumb($label, $title, $link = null)
  42. {
  43. /** @var \Magento\Backend\Block\Widget\Breadcrumbs $block */
  44. $block = $this->layout->getBlock('breadcrumbs');
  45. if ($block) {
  46. $block->addLink($label, $title, $link);
  47. }
  48. return $this;
  49. }
  50. /**
  51. * Add content to content section
  52. *
  53. * @param \Magento\Framework\View\Element\AbstractBlock $block
  54. * @return $this
  55. */
  56. public function addContent(View\Element\AbstractBlock $block)
  57. {
  58. return $this->moveBlockToContainer($block, 'content');
  59. }
  60. /**
  61. * Add block to left container
  62. *
  63. * @param \Magento\Framework\View\Element\AbstractBlock $block
  64. * @return $this
  65. */
  66. public function addLeft(View\Element\AbstractBlock $block)
  67. {
  68. return $this->moveBlockToContainer($block, 'left');
  69. }
  70. /**
  71. * Add javascript to head
  72. *
  73. * @param \Magento\Framework\View\Element\AbstractBlock $block
  74. * @return $this
  75. */
  76. public function addJs(View\Element\AbstractBlock $block)
  77. {
  78. return $this->moveBlockToContainer($block, 'js');
  79. }
  80. /**
  81. * Set specified block as an anonymous child to specified container
  82. *
  83. * The block will be moved to the container from previous parent after all other elements
  84. *
  85. * @param \Magento\Framework\View\Element\AbstractBlock $block
  86. * @param string $containerName
  87. * @return $this
  88. */
  89. protected function moveBlockToContainer(View\Element\AbstractBlock $block, $containerName)
  90. {
  91. $this->layout->setChild($containerName, $block->getNameInLayout(), '');
  92. return $this;
  93. }
  94. }