Commit 61e1db84 authored by Administrator's avatar Administrator 💬

fix: warn when lessons are misconfigured

parent 72670270
...@@ -223,7 +223,7 @@ class M3P2Plugin extends Plugin ...@@ -223,7 +223,7 @@ class M3P2Plugin extends Plugin
$uri = $this->grav['uri']; $uri = $this->grav['uri'];
// var_dump($uri); // best doc ftw // var_dump($uri); // best doc ftw
// GRAV's routing makes use hook 404 pages and do the URL match ourselves // GRAV's routing makes us hook 404 pages and do the URL match ourselves
if ("lessons" != $uri->paths(0)) { if ("lessons" != $uri->paths(0)) {
return; // perhaps not return; // perhaps not
} }
...@@ -239,8 +239,6 @@ class M3P2Plugin extends Plugin ...@@ -239,8 +239,6 @@ class M3P2Plugin extends Plugin
/** @var Pages $pages */ /** @var Pages $pages */
$pages = $this->grav['pages']; $pages = $this->grav['pages'];
// VERY inefficient : TODO: cache this
// $target_pages = $pages->all()->filter(function ($p) use ($lesson_slug) {
$target_pages = array_filter($pages->instances(), function (Page $p) use ($lesson_slug) { $target_pages = array_filter($pages->instances(), function (Page $p) use ($lesson_slug) {
$page_config = $p->header(); $page_config = $p->header();
...@@ -249,6 +247,15 @@ class M3P2Plugin extends Plugin ...@@ -249,6 +247,15 @@ class M3P2Plugin extends Plugin
} }
foreach ($page_config->lessons as $lesson) { foreach ($page_config->lessons as $lesson) {
if ( ! isset($lesson['slug'])) {
trigger_error(
"Misconfigured lesson (missing a slug) in ".($p->filePathClean()),
E_USER_WARNING
);
continue;
}
if ($lesson_slug == $lesson['slug']) { if ($lesson_slug == $lesson['slug']) {
return true; // yay, this page is part of the lesson return true; // yay, this page is part of the lesson
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment