updating menu items in settings when pages is saved

This commit is contained in:
Ro 2021-04-16 22:14:14 -07:00
parent 20cc4abad9
commit 594df048cf
2 changed files with 28 additions and 0 deletions

View file

@ -183,6 +183,9 @@ class Book
if ($task == "create") {
Settings::updateIndex();
}
//once saved, update menu
$body["path"] = $path;
Settings::updateMenu($body);
} else {
$response = [
"message" => "Uh oh. File save problem. Don't panic",

View file

@ -1,5 +1,7 @@
<?php
use function _\find;
use function _\pull;
use function _\remove;
class Settings
{
private $folks;
@ -89,4 +91,27 @@ class Settings
DocTools::writeSettings("../config/settings.json", $settings);
}
public static function updateMenu($body)
{
$settings = self::$settings;
//$menu = $settings["menu"];
$item = [
"title" => $body["title"],
"id" => $body["id"],
"uuid" => $body["uuid"],
"slug" => $body["slug"],
"path" => $body["path"],
];
if ($body["menu"] == "true") {
if (!find($settings["menu"], ["uuid" => $item["uuid"]])) {
array_push($settings["menu"], $item);
}
} else {
if (find($settings["menu"], ["uuid" => $item["uuid"]])) {
pull($settings["menu"], $item);
}
}
DocTools::writeSettings("../config/settings.json", $settings);
}
}