Skip to content

Commit 15e4680

Browse files
committed
Adjust autopublish, autoslug, redirect
1 parent 774b390 commit 15e4680

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ The `$module->moduleId()` method returns the module ID as a BEM class, e.g. `mod
7878

7979
## Options
8080

81+
The following options are available to add to your `site/config/config.php`:
82+
8183
### Default Module Blueprint
8284

83-
By default, the `text` module will be the first/default option in the "Add page" modal.
84-
You can overwrite it in your `site/config/config.php`:
85+
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:
8586

8687
```php
8788
return [
@@ -91,8 +92,7 @@ return [
9192

9293
### Exclude Module Blueprints
9394

94-
By default, all modules will be available in the "Add page" modal.
95-
You can exclude certain modules in your `site/config/config.php`:
95+
By default, all modules will be available in the "Add page" modal. Change this by providing an array of excluded modules:
9696

9797
```php
9898
return [
@@ -115,14 +115,24 @@ return [
115115

116116
### Autopublish Modules
117117

118-
You can turn on automatic publishing for modules in your `site/config/config.php`:
118+
With this option you can skip the draft status and create listed modules directly:
119119

120120
```php
121121
return [
122122
'medienbaecker.modules.autopublish' => true
123123
];
124124
```
125125

126+
### Enable redirect
127+
128+
By default you won't get redirected to the modules pages you create. Change this behaviour by setting the `redirect` option to `true`:
129+
130+
```php
131+
return [
132+
'medienbaecker.modules.redirect' => true
133+
];
134+
```
135+
126136
### Custom Module Model
127137

128138
This plugin creates a `ModulePage` model, overwriting certain methods.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "medienbaecker/kirby-modules",
33
"description": "Easily add modules to your pages",
4-
"version": "2.7.0",
4+
"version": "2.8.0",
55
"license": "MIT",
66
"authors": [
77
{

lib/functions.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,26 @@ function addToModulesRegistry(array $registry, string $name, string $blueprintPa
122122
$blueprintArray['navigation'] = ['status' => 'all', 'template' => 'all'];
123123
}
124124

125-
// Add slug field if autoslug is enabled
126-
if(option('medienbaecker.modules.autoslug') === true) {
127-
if(!array_key_exists('create', $blueprintArray)) {
128-
$blueprintArray['create'] = ['slug' => '{{ page.uniqueModuleSlug }}'];
125+
// Adjust the create blueprint option if it doesn't exist
126+
if(!array_key_exists('create', $blueprintArray)) {
127+
128+
$blueprintArray['create'] = [];
129+
130+
// Add slug field if autoslug is enabled
131+
if(option('medienbaecker.modules.autoslug') === true) {
132+
$blueprintArray['create']['slug'] = '{{ page.uniqueModuleSlug }}';
133+
}
134+
135+
// Set status to listed if autopublish is enabled
136+
if(option('medienbaecker.modules.autopublish') === true) {
137+
$blueprintArray['create']['status'] = 'listed';
129138
}
139+
140+
// Disable redirect if the redirect option is not explicitely set to true
141+
if(option('medienbaecker.modules.redirect') !== true) {
142+
$blueprintArray['create']['redirect'] = false;
143+
}
144+
130145
}
131146

132147
// Add module prefix to blueprint name

lib/models.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
use Kirby\Template\Template;
66

77
class ModulePage extends Page {
8-
public static function create(array $props): Page {
9-
if (option('medienbaecker.modules.autopublish', false)) {
10-
$props['num'] = 9999;
11-
}
12-
return parent::create($props);
13-
}
148
public function parentUrl(): string {
159
return $this->parents()->count() > 0 ? $this->parents()->first()->url() : $this->site()->url();
1610
}

0 commit comments

Comments
 (0)