From 15e46803a05ed88fafbc1f45afccb9ecae17852f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Gu=CC=88nther?= Date: Thu, 9 May 2024 18:01:08 +0200 Subject: [PATCH] Adjust autopublish, autoslug, redirect --- README.md | 20 +++++++++++++++----- composer.json | 2 +- lib/functions.php | 23 +++++++++++++++++++---- lib/models.php | 6 ------ 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 80c4814..c9396d9 100644 --- a/README.md +++ b/README.md @@ -78,10 +78,11 @@ The `$module->moduleId()` method returns the module ID as a BEM class, e.g. `mod ## Options +The following options are available to add to your `site/config/config.php`: + ### Default Module Blueprint -By default, the `text` module will be the first/default option in the "Add page" modal. -You can overwrite it in your `site/config/config.php`: +By default, the `text` module will be the first/default option in the "Add page" modal. You can change this behaviour by setting your own default module: ```php return [ @@ -91,8 +92,7 @@ return [ ### Exclude Module Blueprints -By default, all modules will be available in the "Add page" modal. -You can exclude certain modules in your `site/config/config.php`: +By default, all modules will be available in the "Add page" modal. Change this by providing an array of excluded modules: ```php return [ @@ -115,7 +115,7 @@ return [ ### Autopublish Modules -You can turn on automatic publishing for modules in your `site/config/config.php`: +With this option you can skip the draft status and create listed modules directly: ```php return [ @@ -123,6 +123,16 @@ return [ ]; ``` +### Enable redirect + +By default you won't get redirected to the modules pages you create. Change this behaviour by setting the `redirect` option to `true`: + +```php +return [ + 'medienbaecker.modules.redirect' => true +]; +``` + ### Custom Module Model This plugin creates a `ModulePage` model, overwriting certain methods. diff --git a/composer.json b/composer.json index bb67c7c..030bc75 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "medienbaecker/kirby-modules", "description": "Easily add modules to your pages", - "version": "2.7.0", + "version": "2.8.0", "license": "MIT", "authors": [ { diff --git a/lib/functions.php b/lib/functions.php index 7d80416..e745785 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -122,11 +122,26 @@ function addToModulesRegistry(array $registry, string $name, string $blueprintPa $blueprintArray['navigation'] = ['status' => 'all', 'template' => 'all']; } - // Add slug field if autoslug is enabled - if(option('medienbaecker.modules.autoslug') === true) { - if(!array_key_exists('create', $blueprintArray)) { - $blueprintArray['create'] = ['slug' => '{{ page.uniqueModuleSlug }}']; + // Adjust the create blueprint option if it doesn't exist + if(!array_key_exists('create', $blueprintArray)) { + + $blueprintArray['create'] = []; + + // Add slug field if autoslug is enabled + 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) { + $blueprintArray['create']['status'] = 'listed'; } + + // Disable redirect if the redirect option is not explicitely set to true + if(option('medienbaecker.modules.redirect') !== true) { + $blueprintArray['create']['redirect'] = false; + } + } // Add module prefix to blueprint name diff --git a/lib/models.php b/lib/models.php index 7b78b33..0bfe670 100644 --- a/lib/models.php +++ b/lib/models.php @@ -5,12 +5,6 @@ use Kirby\Template\Template; class ModulePage extends Page { - public static function create(array $props): Page { - if (option('medienbaecker.modules.autopublish', false)) { - $props['num'] = 9999; - } - return parent::create($props); - } public function parentUrl(): string { return $this->parents()->count() > 0 ? $this->parents()->first()->url() : $this->site()->url(); }