updating menu items in settings when pages is saved

beta
Ro 4 years ago
parent 20cc4abad9
commit 594df048cf

@ -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",

@ -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);
}
}

Loading…
Cancel
Save