-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Expand file tree
/
Copy pathPageService.php
More file actions
67 lines (62 loc) · 1.69 KB
/
PageService.php
File metadata and controls
67 lines (62 loc) · 1.69 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
<?php
declare(strict_types=1);
/**
* Copyright 2015 Adobe
* All Rights Reserved.
*/
namespace Magento\Cms\Model\Page\Service;
use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Api\PageRepositoryInterface;
use Magento\Cms\Model\Page\CustomLayoutManagerInterface;
use Magento\Cms\Model\PageFactory;
use Magento\Framework\Exception\LocalizedException;
/**
* Cms Page Service Class
*/
class PageService
{
/**
* @param PageRepositoryInterface $pageRepository
* @param PageFactory $pageFactory
* @param CustomLayoutManagerInterface $customLayoutManager
*/
public function __construct(
private readonly PageRepositoryInterface $pageRepository,
private readonly PageFactory $pageFactory,
private readonly CustomLayoutManagerInterface $customLayoutManager,
) {
}
/**
* To get the page by its ID. If the page not exists, a new page instance is returned
*
* @param int $id
* @return PageInterface
*/
public function getPageById(int $id): PageInterface
{
try {
return $this->pageRepository->getById($id);
} catch (LocalizedException) {
return $this->pageFactory->create();
}
}
/**
* To create pagefactory class
*
* @return PageInterface
*/
public function createPageFactory(): PageInterface
{
return $this->pageFactory->create();
}
/**
* Fetches the available custom layouts for a given page.
*
* @param PageInterface $page
* @return array
*/
public function fetchAvailableCustomLayouts(PageInterface $page): array
{
return $this->customLayoutManager->fetchAvailableFiles($page);
}
}