Skip to content

Commit

Permalink
fix(page-section): Fix parent and name
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco (Valandur) committed Feb 27, 2019
1 parent 883e493 commit e469754
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/PageSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class PageSection extends DataObject
];

public function Parent() {
return DataObject::get_by_id($this->__ParentClass, $this->__ParentID);
$parent = DataObject::get_by_id($this->__ParentClass, $this->__ParentID);
if ($parent == null) {
$parent = Versioned::get_latest_version($this->__ParentClass, $this->__ParentID);
}
return $parent;
}

public function onBeforeWrite() {
Expand Down Expand Up @@ -78,6 +82,10 @@ public function forTemplate()
* @return string
*/
public function getName() {
if ($this->__Name) {
return $this->__Name;
}

$parent = $this->Parent();
// TODO: Find out why this happens
if (!method_exists($parent, "getPageSectionNames")) {
Expand All @@ -98,7 +106,7 @@ public function getName() {
* @param string $section The section for which to get the allowed child classes.
* @return string[]
*/
public function getAllowedPageElements($section = "Main") {
return $this->Parent()->getAllowedPageElements($section);
public function getAllowedPageElements() {
return $this->Parent()->getAllowedPageElements($this->__Name);
}
}

0 comments on commit e469754

Please sign in to comment.