-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathPage.php
122 lines (107 loc) · 3.63 KB
/
Page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*
* Glory to Ukraine! Glory to the heroes!
*/
namespace Magefan\Blog\Helper;
use Magento\Framework\App\Action\Action;
/**
* Magefan Blog Helper
*/
class Page extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
* Design package instance
*
* @var \Magento\Framework\View\DesignInterface
*/
protected $_design;
/**
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
*/
protected $_localeDate;
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* Constructor
*
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Framework\View\DesignInterface $design
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\View\DesignInterface $design,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->_design = $design;
$this->_localeDate = $localeDate;
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* Return result blog page
*
* @param Action $action
* @param \Magento\Framework\Model\AbstractModel $page
* @return \Magento\Framework\View\Result\Page|bool
*/
public function prepareResultPage(Action $action, $page)
{
if ($page->getCustomThemeFrom() && $page->getCustomThemeTo()) {
$inRange = $this->_localeDate->isScopeDateInInterval(
null,
$page->getCustomThemeFrom(),
$page->getCustomThemeTo()
);
} else {
$inRange = false;
}
if ($page->getCustomTheme()) {
if ($inRange) {
$this->_design->setDesignTheme($page->getCustomTheme());
}
}
/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
// dispatch event
$this->_eventManager->dispatch('magefan_blog_page_render_before', [
'action' => $action,
'page' => $page,
'result_page' => $resultPage,
]);
if ($inRange
&& $page->getCustomLayout()
&& $page->getCustomLayout() != 'empty'
) {
$handle = $page->getCustomLayout();
} else {
$handle = $page->getPageLayout();
}
if ($handle) {
$resultPage->getConfig()->setPageLayout($handle);
}
$fullActionName = $action->getRequest()->getFullActionName();
$resultPage->addHandle($fullActionName);
$resultPage->addPageLayoutHandles(['id' => str_replace('/', '_', (string)$page->getIdentifier())]);
$this->_eventManager->dispatch(
$fullActionName . '_render',
['page' => $page, 'controller_action' => $action]
);
if ($inRange && $page->getCustomLayoutUpdateXml()) {
$layoutUpdate = $page->getCustomLayoutUpdateXml();
} else {
$layoutUpdate = $page->getLayoutUpdateXml();
}
if ($layoutUpdate) {
$resultPage->getLayout()->getUpdate()->addUpdate($layoutUpdate);
}
return $resultPage;
}
}