Refactor getFirstPage

This commit is contained in:
Stéphane Goetz 2015-07-18 01:14:44 +02:00
parent ce109d0429
commit 71d1041cb8
1 changed files with 20 additions and 16 deletions

View File

@ -87,7 +87,7 @@ abstract class Entry
} }
/** /**
* @return Content * @return Content|false
*/ */
public function getFirstPage() public function getFirstPage()
{ {
@ -95,25 +95,29 @@ abstract class Entry
return $this->first_page; return $this->first_page;
} }
if ($this instanceof Directory) { if (!$this instanceof Directory) {
foreach ($this->value as $node) { return false;
if ($node instanceof Content) { }
if (!count($node->getParents()) && $node->title == 'index') {
//the homepage should not count as first page
continue;
}
$this->first_page = $node; foreach ($this->value as $node) {
return $node; if ($node instanceof Content) {
} if (!count($node->getParents()) && $node->title == 'index') {
} //the homepage should not count as first page
foreach ($this->value as $node) { continue;
if ($node instanceof Directory && $page = $node->getFirstPage()) {
$this->first_page = $page;
return $page;
} }
$this->first_page = $node;
return $node;
} }
} }
foreach ($this->value as $node) {
if ($node instanceof Directory && $page = $node->getFirstPage()) {
$this->first_page = $page;
return $page;
}
}
return false; return false;
} }