diff --git a/docs/options.md b/docs/options.md index e0bc1227..3c76f8fd 100644 --- a/docs/options.md +++ b/docs/options.md @@ -29,6 +29,10 @@ The following config options are available: // set your own string as prefix in the Panel dialog // (disable completely by setting to `false`) 'site' => 'my.short.domain' + + // set default HTTP status code the redirect will respond with + // Default: null (which disables the redirect) + 'defaultStatus' => ..., ] ``` diff --git a/src/Retour/Panel/RedirectCreateDrawer.php b/src/Retour/Panel/RedirectCreateDrawer.php index e22e63f6..f0c3d3e8 100644 --- a/src/Retour/Panel/RedirectCreateDrawer.php +++ b/src/Retour/Panel/RedirectCreateDrawer.php @@ -58,6 +58,7 @@ protected function fields(): array 'label' => I18n::translate('retour.redirects.status'), 'options' => $codes, 'width' => '1/2', + 'default' => Retour::instance()->option('defaultStatus'), 'help' => I18n::template('retour.redirects.status.help', [ 'docs' => 'https://distantnative.com/retour-for-kirby/redirects#status' ]) diff --git a/src/Retour/Panel/RedirectEditDrawer.php b/src/Retour/Panel/RedirectEditDrawer.php index 65b624f3..411a24ce 100644 --- a/src/Retour/Panel/RedirectEditDrawer.php +++ b/src/Retour/Panel/RedirectEditDrawer.php @@ -4,6 +4,7 @@ use Kirby\Retour\Redirect; use Kirby\Toolkit\I18n; +use Kirby\Toolkit\A; /** * @package Retour for Kirby @@ -24,6 +25,9 @@ public function load(): array { $fields = $this->fields(); + // remove default value for status + $fields['status'] = A::merge($fields['status'], ['default' => null]); + // set autofocus if specific column cell was passed if ($column = $this->kirby()->request()->get('column')) { foreach ($fields as $name => $field) { diff --git a/src/panel/components/Fields/StatusField.vue b/src/panel/components/Fields/StatusField.vue index 0a76074e..030f0d62 100644 --- a/src/panel/components/Fields/StatusField.vue +++ b/src/panel/components/Fields/StatusField.vue @@ -23,5 +23,10 @@ import color from "../../mixins/color.js"; export default { extends: "k-select-field", mixins: [color], + mounted() { + if (!this.value && this.default) { + this.$emit('input', this.default); + } + } };