forked from wintercms/wn-pages-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChildPages.php
60 lines (53 loc) · 1.95 KB
/
ChildPages.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
<?php namespace Winter\Pages\Components;
use Cms\Classes\ComponentBase;
class ChildPages extends ComponentBase
{
/**
* @var \Winter\Pages\Components\StaticPage A reference to the static page component
*/
protected $staticPageComponent;
/**
* @var array Array of \Winter\Pages\Classes\Page references to the child static page objects for the current page
*/
protected $childPages;
/**
* @var array Child pages data
* [
* 'url' => '',
* 'title' => '',
* 'page' => \Winter\Pages\Classes\Page,
* 'viewBag' => array,
* 'is_hidden' => bool,
* 'navigation_hidden' => bool,
* ]
*/
public $pages = [];
public function componentDetails()
{
return [
'name' => 'winter.pages::lang.component.child_pages_name',
'description' => 'winter.pages::lang.component.child_pages_description'
];
}
public function onRun()
{
// Check if the staticPage component is attached to the rendering template
$this->staticPageComponent = $this->findComponentByName('staticPage');
if ($this->staticPageComponent->pageObject) {
$this->childPages = $this->staticPageComponent->pageObject->getChildren();
if ($this->childPages) {
foreach ($this->childPages as $childPage) {
$viewBag = $childPage->viewBag;
$this->pages = array_merge($this->pages, [[
'url' => @$viewBag['url'],
'title' => @$viewBag['title'],
'page' => $childPage,
'viewBag' => $viewBag,
'is_hidden' => @$viewBag['is_hidden'],
'navigation_hidden' => @$viewBag['navigation_hidden'],
]]);
}
}
}
}
}