Improved logic for saving and added 'guess' the visibility functionality

This commit is contained in:
Andy Miller
2015-08-05 15:30:30 -06:00
parent ac6a79f069
commit 7e1b5db4ee
3 changed files with 39 additions and 14 deletions

View File

@@ -503,8 +503,9 @@ class Admin
if (isset($this->session->{$page->route()})) {
// Found the type and header from the session.
$data = $this->session->{$page->route()};
$visible = isset($data['visible']) && $data['visible'] != '' ? (bool) $data['visible'] : $this->guessVisibility($page);
$page->name($data['type'] . '.md');
$page->header(['title' => $data['title'], 'visible' => $data['visible']]);
$page->header(['title' => $data['title'], 'visible' => $visible]);
$page->frontmatter(Yaml::dump((array) $page->header()));
} else {
// Find out the type by looking at the parent.
@@ -518,6 +519,24 @@ class Admin
return $page;
}
/**
* Guess the intended visibility status based on other sibling folders
*
* @param \Grav\Common\Page\Page $page
*
* @return bool
*/
public function guessVisibility(Page $page)
{
$children = $page->parent()->children();
foreach ($children as $child) {
if ($child->order()) {
return true;
}
}
return false;
}
/**
* Static helper method to return current route.
*