-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathAddBlock.php
More file actions
116 lines (104 loc) · 3.57 KB
/
AddBlock.php
File metadata and controls
116 lines (104 loc) · 3.57 KB
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
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_BannerSlider
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\BannerSlider\Observer;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\View\Layout;
use Mageplaza\BannerSlider\Block\Slider;
use Mageplaza\BannerSlider\Helper\Data;
/**
* Class AddBlock
* @package Mageplaza\AutoRelated\Observer
*/
class AddBlock implements ObserverInterface
{
/**
* @var RequestInterface
*/
protected $request;
/**
* @var Data
*/
protected $helperData;
/**
* AddBlock constructor.
*
* @param RequestInterface $request
* @param Data $helperData
*/
public function __construct(
RequestInterface $request,
Data $helperData
) {
$this->request = $request;
$this->helperData = $helperData;
}
/**
* @param Observer $observer
*
* @return $this
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function execute(Observer $observer)
{
if (!$this->helperData->isEnabled()) {
return $this;
}
$type = array_search($observer->getEvent()->getElementName(), [
'header' => 'header',
'content' => 'content',
'page-top' => 'page.top',
'footer-container' => 'footer-container',
'sidebar' => 'catalog.leftnav'
], true);
if ($type !== false) {
/** @var Layout $layout */
$layout = $observer->getEvent()->getLayout();
$fullActionName = $this->request->getFullActionName();
$output = $observer->getTransport()->getOutput();
foreach ($this->helperData->getActiveSliders() as $slider) {
if (!empty($slider->getLocation())) {
$locations = array_filter(explode(',', $slider->getLocation()));
foreach ($locations as $value) {
list($pageType, $location) = explode('.', $value);
if (($fullActionName === $pageType || $pageType === 'allpage') &&
strpos($location, $type) !== false
) {
$content = $layout->createBlock(Slider::class)
->setSlider($slider)
->toHtml();
if (strpos($location, 'top') !== false) {
$output = "<div id=\"mageplaza-bannerslider-block-before-{$type}-{$slider->getId()}\">
$content</div>" . $output;
} else {
$output .= "<div id=\"mageplaza-bannerslider-block-after-{$type}-{$slider->getId()}\">
$content</div>";
}
}
}
}
}
$observer->getTransport()->setOutput($output);
}
return $this;
}
}