mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-12-24 09:20:41 +01:00
Improved logic for saving and added 'guess' the visibility functionality
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user