Skip to content

Commit

Permalink
Adjust autopublish, autoslug, redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
medienbaecker committed May 9, 2024
1 parent 774b390 commit 15e4680
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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 [
Expand All @@ -115,14 +115,24 @@ 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 [
'medienbaecker.modules.autopublish' => true
];
```

### 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.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
23 changes: 19 additions & 4 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions lib/models.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 15e4680

Please sign in to comment.