cms icon indicating copy to clipboard operation
cms copied to clipboard

Slug being generated, even when field is hidden

Open ssyberg opened this issue 8 months ago • 2 comments

Bug description

I'm trying to disable slugs on a subset of entries in a collection but new entires appear to still have slugs generated.

How to reproduce

  1. Create blueprint with a slug field, slug field is set to auto generate based on title, but conditionally visible based on a "has profile" boolean, if slug is hidden I expect it to be empty and remain empty
  2. Create collection with slugs set to not required
  3. Create a new entry with "has profile" false
  4. New entry is created and has slug set

Stranger still, and this is probably just something I don't understand about revisions, but I don't see a slug value set on the content record at all, but I do see it on the revision record

Logs


Environment

Environment
Application Name: <redacted>
Laravel Version: 10.48.27
PHP Version: 8.3.17
Composer Version: 2.8.6
Environment: local
Debug Mode: ENABLED
URL: <redacted>
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 4
Sites: 1
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.46.0 PRO

Statamic Addons
alt-design/alt-redirect: 1.3.3
aryehraber/statamic-logbook: 3.3.0
jacksleight/statamic-bard-texstyle: 3.4.1
stillat/relationships: 2.2.1

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

ssyberg avatar Mar 12 '25 13:03 ssyberg

You'll need to remove the Slug field from your blueprint, instead of just marking it as hidden.

duncanmcclean avatar Mar 12 '25 18:03 duncanmcclean

You'll need to remove the Slug field from your blueprint, instead of just marking it as hidden.

The slug is an optional field on this blueprint, removing it doesn't make sense.

ssyberg avatar Mar 12 '25 18:03 ssyberg

This has gotten weird recently, I added this to an entry saving listener to nullify the slug on save when it's empty: $entry->slug(null);

This works great and I wrote an artistan command to spin through and fix all the incorrect slugs. I went back a few days later and all the slugs were populated again, but this time with the entry id!? I can't figure out how this happening / what automated process would be resaving all these entries (it's happening to ~2000 entries that I just nullified the slug on) and why it thinks I want a slug with a entry id... any ideas?

ssyberg avatar Aug 11 '25 21:08 ssyberg

When you save an entry without a slug, the ID will be used as the filename.

When Statamic reads your files again (eg. after you clear the Stache), it'll take whatever is in the filename and use that as the slug. It doesn't take the fact the ID and the "slug" are the same into consideration as folks might be doing that on purpose.

duncanmcclean avatar Aug 12 '25 08:08 duncanmcclean

Alright so that solves the mystery, it's the stache that's misbehaving, I'll update the bug details

ssyberg avatar Aug 12 '25 12:08 ssyberg

@duncanmcclean can you think of any way of preventing this? In our use case we really need the slug to remain empty in the stache. We've turned off auto generatre, we've made the filed optional, but it's still happening. Is there an event we can hook into as a workaround or a some stache config that could prevent this until the bug is addressed?

ssyberg avatar Aug 12 '25 12:08 ssyberg

Ok after more investigation this all seems to have stemmed from a misunderstanding about the required slugs setting at the collection level. I'm going to close this for now, I will reopen if I discover something.

ssyberg avatar Aug 12 '25 12:08 ssyberg