From 1f328e674e21bdeb79a8824c734a9728acab4aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Gu=CC=88nther?= Date: Sat, 28 Dec 2024 17:28:05 +0100 Subject: [PATCH] Add default icon: "box" --- lib/functions.php | 57 +++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index 68c1467..9b70a5b 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -5,7 +5,8 @@ use Kirby\Toolkit\Str; use Kirby\Data\Yaml; -function createModuleRegistry() { +function createModuleRegistry() +{ $registry = ['blueprints' => [], 'templates' => [], 'pageModels' => []]; @@ -18,8 +19,8 @@ function createModuleRegistry() { // ---------------------------------------------------------------------- foreach (Dir::dirs($modulesFolder) as $folder) { - $blueprintPath = $modulesFolder . "/". $folder . "/" . $folder . ".yml"; - $templatePath = $modulesFolder . "/". $folder . "/" . $folder . ".php"; + $blueprintPath = $modulesFolder . "/" . $folder . "/" . $folder . ".yml"; + $templatePath = $modulesFolder . "/" . $folder . "/" . $folder . ".php"; $registry = addToModulesRegistry($registry, $folder, $blueprintPath, $templatePath); } @@ -41,14 +42,14 @@ function createModuleRegistry() { // Legacy registry (deprecated) // ---------------------------------------------------------------------- - $moduleBlueprints = array_filter(kirby()->blueprints(), function($blueprint) { + $moduleBlueprints = array_filter(kirby()->blueprints(), function ($blueprint) { return Str::startsWith($blueprint, 'module.'); }); // Check if there are any module blueprints and throw a deprecation warning - if(count($moduleBlueprints)) { + if (count($moduleBlueprints)) { deprecated('This folder structure is deprecated. Please move your module blueprints to site/blueprints/modules/ and your module templates to site/snippets/modules/.'); - foreach($moduleBlueprints as $moduleBlueprint) { + foreach ($moduleBlueprints as $moduleBlueprint) { $blueprintPath = $blueprintsFolder . "/pages/" . $moduleBlueprint . ".yml"; $templatePath = $snippetsFolder . "/modules/" . $moduleBlueprint . ".php"; $registry = addToModulesRegistry($registry, $moduleBlueprint, $blueprintPath, $templatePath); @@ -60,16 +61,17 @@ function createModuleRegistry() { // ---------------------------------------------------------------------- $blueprintNames = array_keys($registry['blueprints']); - $blueprintNames = array_map(function($blueprintName) { + $blueprintNames = array_map(function ($blueprintName) { return Str::replace($blueprintName, 'pages/', ''); }, $blueprintNames); - foreach($registry['blueprints'] as &$blueprint) { - if( + foreach ($registry['blueprints'] as &$blueprint) { + if ( !isset($blueprint['options']) || ( - is_array($blueprint['options']) && !isset($blueprint['options']['changeTemplate'] - )) + is_array($blueprint['options']) && !isset( + $blueprint['options']['changeTemplate'] + )) ) { $blueprint['options']['changeTemplate'] = $blueprintNames; } @@ -78,7 +80,7 @@ function createModuleRegistry() { // ---------------------------------------------------------------------- // Add modules container blueprint with pages section and redirect field // ---------------------------------------------------------------------- - + $registry['blueprints']['pages/modules'] = [ 'title' => 'Modules', 'options' => [ @@ -97,7 +99,7 @@ function createModuleRegistry() { ] ], ]; - + // ---------------------------------------------------------------------- // Add modules container model // ---------------------------------------------------------------------- @@ -105,18 +107,18 @@ function createModuleRegistry() { $registry['pageModels']['modules'] = 'ModulesPage'; return $registry; - } -function addToModulesRegistry(array $registry, string $name, string $blueprintPath, string $templatePath) { +function addToModulesRegistry(array $registry, string $name, string $blueprintPath, string $templatePath) +{ // Check if blueprint already exists in registry - if(array_key_exists('pages/module.'. $name, $registry['blueprints'])) { + if (array_key_exists('pages/module.' . $name, $registry['blueprints'])) { return; } // Check if blueprint exists - if(!F::exists($blueprintPath)) { + if (!F::exists($blueprintPath)) { return; } @@ -124,7 +126,7 @@ function addToModulesRegistry(array $registry, string $name, string $blueprintPa $blueprintArray = Yaml::read($blueprintPath); // Set up default values for status and navigation - if(!array_key_exists('status', $blueprintArray)) { + if (!array_key_exists('status', $blueprintArray)) { $blueprintArray['status'] = [ 'draft' => [ 'text' => false @@ -134,34 +136,36 @@ function addToModulesRegistry(array $registry, string $name, string $blueprintPa ] ]; } - if(!array_key_exists('navigation', $blueprintArray)) { + if (!array_key_exists('navigation', $blueprintArray)) { $blueprintArray['navigation'] = ['status' => 'all', 'template' => 'all']; } + if (!array_key_exists('icon', $blueprintArray)) { + $blueprintArray['icon'] = "box"; + } // Adjust the create blueprint option if it doesn't exist - if(!array_key_exists('create', $blueprintArray)) { + if (!array_key_exists('create', $blueprintArray)) { $blueprintArray['create'] = []; // Add slug field if autoslug is enabled - if(option('medienbaecker.modules.autoslug') === true) { + if (option('medienbaecker.modules.autoslug') === true) { $blueprintArray['create']['slug'] = '{{ page.uniqueModuleSlug }}'; } // Set status to listed if autopublish is enabled - if(option('medienbaecker.modules.autopublish') === true) { + if (option('medienbaecker.modules.autopublish') === true) { $blueprintArray['create']['status'] = 'listed'; } // Disable redirect if the redirect option is not explicitely set to true - if(option('medienbaecker.modules.redirect') !== true) { + if (option('medienbaecker.modules.redirect') !== true) { $blueprintArray['create']['redirect'] = false; } - } // Add module prefix to blueprint name - if(Str::startsWith($name, 'module.') === false) { + if (Str::startsWith($name, 'module.') === false) { $name = 'module.' . $name; } @@ -171,5 +175,4 @@ function addToModulesRegistry(array $registry, string $name, string $blueprintPa $registry['pageModels'][$name] = option('medienbaecker.modules.model', 'ModulePage'); return $registry; - -} \ No newline at end of file +}