Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a default status code for new redirects (#360) #361

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' => ...,
Comment on lines +34 to +35
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Default: null (which disables the redirect)
'defaultStatus' => ...,
// Default: `null` (which disables the redirect)
'status' => 308,

]
```

Expand Down
1 change: 1 addition & 0 deletions src/Retour/Panel/RedirectCreateDrawer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected function fields(): array
'label' => I18n::translate('retour.redirects.status'),
'options' => $codes,
'width' => '1/2',
'default' => Retour::instance()->option('defaultStatus'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'default' => Retour::instance()->option('defaultStatus'),
'default' => Retour::instance()->option('status'),

'help' => I18n::template('retour.redirects.status.help', [
'docs' => 'https://distantnative.com/retour-for-kirby/redirects#status'
])
Expand Down
4 changes: 4 additions & 0 deletions src/Retour/Panel/RedirectEditDrawer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Kirby\Retour\Redirect;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\A;

/**
* @package Retour for Kirby
Expand All @@ -24,6 +25,9 @@ public function load(): array
{
$fields = $this->fields();

// remove default value for status
$fields['status'] = A::merge($fields['status'], ['default' => null]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$fields['status'] = A::merge($fields['status'], ['default' => null]);
unset($fields['status']['default']);


// set autofocus if specific column cell was passed
if ($column = $this->kirby()->request()->get('column')) {
foreach ($fields as $name => $field) {
Expand Down
5 changes: 5 additions & 0 deletions src/panel/components/Fields/StatusField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
</script>