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

[5.x] Ability to opt out of async slug behavior, and opt out in field settings #10075

Merged
merged 2 commits into from
May 14, 2024
Merged
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
1 change: 1 addition & 0 deletions resources/js/components/fieldtypes/SlugFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:from="source"
:separator="separator"
:language="language"
:async="config.async"
@slugifying="syncing = true"
@slugified="syncing = false"
v-model="slug"
Expand Down
17 changes: 16 additions & 1 deletion resources/js/components/slugs/Slugify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ export default {
enabled: {
type: Boolean,
default: true
},
async: {
type: Boolean,
default: true
}
},

data() {
let slugifier = this.$slug.in(this.language).separatedBy(this.separator);
if (this.async) slugifier.async();

return {
slugifier: this.$slug.async().in(this.language).separatedBy(this.separator),
slugifier,
slug: null,
shouldSlugify: this.enabled && !this.to
}
Expand Down Expand Up @@ -74,6 +81,14 @@ export default {
},

slugify() {
if (! this.async) {
return new Promise((resolve, reject) => {
const slug = this.slugifier.create(this.from);
this.slug = slug;
resolve(slug);
});
}

return new Promise((resolve, reject) => {
this.$emit('slugifying');
this.slugifier.create(this.from).then(slug => {
Expand Down
1 change: 1 addition & 0 deletions src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ public static function commonFieldOptions(): Fields
'instructions' => __('statamic::messages.fields_handle_instructions'),
'type' => 'slug',
'from' => 'display',
'async' => false,
'separator' => '_',
'validate' => [
'required',
Expand Down
Loading