Skip to content

Commit

Permalink
[5.x] Ability to opt out of async slug behavior, and opt out in field…
Browse files Browse the repository at this point in the history
… settings (#10075)
  • Loading branch information
jasonvarga authored May 14, 2024
1 parent 5497ef2 commit d140dd4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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

0 comments on commit d140dd4

Please sign in to comment.