Skip to content

Commit 261ed67

Browse files
committed
Merge pull request #35 from Tom-Alexander/feature/parent-config-getter
UPDATE: Added array check
2 parents 43fe8b1 + dda2b63 commit 261ed67

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

code/Extensions/CatalogDataObjectExtension.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function updateCMSFields(FieldList $fields)
5252
$fields->removeByName('Version');
5353
$fields->removeByName('Versions');
5454

55-
$parentClass = $this->owner->stat('parentClass');
55+
$parentClass = $this->getParentClasses();
5656

5757
if ($pages = DataObject::get()->filter(array('ClassName' => array_values($parentClass)))) {
5858

@@ -188,6 +188,22 @@ public function doUnpublish()
188188
return true;
189189
}
190190

191+
/**
192+
* Returns the parent classes defined from the config as an array
193+
* @return array
194+
*/
195+
public function getParentClasses()
196+
{
197+
$parentClasses = $this->owner->stat('parentClass');
198+
199+
if(!is_array($parentClasses)) {
200+
return array($parentClasses);
201+
}
202+
203+
return $parentClasses;
204+
205+
}
206+
191207
/**
192208
* Gets the fieldname for the sort column. Uses in owner's config for $sort_column
193209
*

code/Extensions/CatalogPageExtension.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function isPublishedNice()
5656
*/
5757
public function updateCMSFields(FieldList $fields)
5858
{
59-
$parentClass = $this->owner->stat('parentClass');
59+
$parentClass = $this->getParentClasses();
6060

6161
if ($pages = $this->getCatalogParents()) {
6262

@@ -76,6 +76,22 @@ public function updateCMSFields(FieldList $fields)
7676
}
7777
}
7878

79+
/**
80+
* Returns the parent classes defined from the config as an array
81+
* @return array
82+
*/
83+
public function getParentClasses()
84+
{
85+
$parentClasses = $this->owner->stat('parentClass');
86+
87+
if(!is_array($parentClasses)) {
88+
return array($parentClasses);
89+
}
90+
91+
return $parentClasses;
92+
93+
}
94+
7995
/**
8096
* Gets the fieldname for the sort column. As we're on a subclass of SiteTree we assume 'Sort' as default.
8197
* Can be overwritten using $sort_column param on extended class.
@@ -97,7 +113,7 @@ public function getSortFieldname()
97113
*/
98114
public function getCatalogParents()
99115
{
100-
$parentClass = $this->owner->stat('parentClass');
116+
$parentClass = $this->getParentClasses();
101117
if (count($parentClass)) {
102118
$pages = SiteTree::get()->filter(array('ClassName' => array_values($parentClass)));
103119
return $pages;

0 commit comments

Comments
 (0)