-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLayout.php
75 lines (66 loc) · 1.88 KB
/
Layout.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
<?php
/**
* @author Artemii Karkusha
* @copyright Copyright (c) (https://www.linkedin.com/in/artemiy-karkusha/)
*/
declare(strict_types=1);
namespace ArtemiiKarkusha\AdobeCommercePreparingToCertification\Controller\ActionsResults;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Result\Layout as ResultLayout;
use Magento\Framework\View\Result\LayoutFactory as ResultLayoutFactory;
use Psr\Log\LoggerInterface;
/**
* Controller example with result object the Layout
*/
class Layout implements HttpGetActionInterface
{
/**
* @param ResultLayoutFactory $resultLayoutFactory
* @param LoggerInterface $logger
* @param array $handles
*/
public function __construct(
private ResultLayoutFactory $resultLayoutFactory,
private LoggerInterface $logger,
private array $handles = []
) {
}
/**
* @inheritDoc
*/
public function execute(): ResultInterface
{
return $this->loadUpdatedLayoutByHandles();
}
/**
* Load updated layout by handles
*
* @return ResultLayout
*/
private function loadUpdatedLayoutByHandles(): ResultLayout
{
$resultLayout = $this->resultLayoutFactory->create();
$resultLayout->addDefaultHandle();
try {
$resultLayout->getLayout()->getUpdate()->load($this->getHandles());
} catch (LocalizedException $localizedException) {
$this->logger->error(
$localizedException->getMessage(),
[__CLASS__]
);
}
return $resultLayout;
}
/**
* Get handles
*
* @return string[]
*/
private function getHandles(): array
{
return $this->handles;
}
}