Skip to content

Commit

Permalink
Merge pull request #35 from Tom-Alexander/feature/parent-config-getter
Browse files Browse the repository at this point in the history
UPDATE: Added array check
  • Loading branch information
stevie-mayhew committed Oct 24, 2015
2 parents 43fe8b1 + dda2b63 commit 261ed67
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
18 changes: 17 additions & 1 deletion code/Extensions/CatalogDataObjectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function updateCMSFields(FieldList $fields)
$fields->removeByName('Version');
$fields->removeByName('Versions');

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

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

Expand Down Expand Up @@ -188,6 +188,22 @@ public function doUnpublish()
return true;
}

/**
* Returns the parent classes defined from the config as an array
* @return array
*/
public function getParentClasses()
{
$parentClasses = $this->owner->stat('parentClass');

if(!is_array($parentClasses)) {
return array($parentClasses);
}

return $parentClasses;

}

/**
* Gets the fieldname for the sort column. Uses in owner's config for $sort_column
*
Expand Down
20 changes: 18 additions & 2 deletions code/Extensions/CatalogPageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function isPublishedNice()
*/
public function updateCMSFields(FieldList $fields)
{
$parentClass = $this->owner->stat('parentClass');
$parentClass = $this->getParentClasses();

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

Expand All @@ -76,6 +76,22 @@ public function updateCMSFields(FieldList $fields)
}
}

/**
* Returns the parent classes defined from the config as an array
* @return array
*/
public function getParentClasses()
{
$parentClasses = $this->owner->stat('parentClass');

if(!is_array($parentClasses)) {
return array($parentClasses);
}

return $parentClasses;

}

/**
* Gets the fieldname for the sort column. As we're on a subclass of SiteTree we assume 'Sort' as default.
* Can be overwritten using $sort_column param on extended class.
Expand All @@ -97,7 +113,7 @@ public function getSortFieldname()
*/
public function getCatalogParents()
{
$parentClass = $this->owner->stat('parentClass');
$parentClass = $this->getParentClasses();
if (count($parentClass)) {
$pages = SiteTree::get()->filter(array('ClassName' => array_values($parentClass)));
return $pages;
Expand Down

0 comments on commit 261ed67

Please sign in to comment.