statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.11k stars 539 forks source link

Slugs are shown in collection tables even with listable set to `Hidden by default` #10792

Open robdekort opened 2 months ago

robdekort commented 2 months ago

Bug description

Slugs are shown in collection tables even with listable set to Hidden by default

How to reproduce

Create a collection Set slugs to Hidden by default View collection table See slugs

Logs

No response

Environment

Environment
Laravel Version: 11.23.2
PHP Version: 8.2.23
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Timezone: Europe/Amsterdam
Locale: en

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

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

Livewire
Livewire: v3.5.6

Statamic
Addons: 5
Sites: 3 (English, Dutch, German)
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.25.0 PRO

Statamic Addons
jonassiewertsen/statamic-livewire: 3.8.0
studio1902/statamic-peak-browser-appearance: 3.5.0
studio1902/statamic-peak-commands: 8.8.0
studio1902/statamic-peak-seo: 8.16.0
studio1902/statamic-peak-tools: 6.3.2

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

duncanmcclean commented 2 months ago

Do you have any preferences set?

robdekort commented 2 months ago

Nope! Can't reproduce it then?

duncanmcclean commented 2 months ago

Yeah, it seems to be working fine for me. I don't have any preferences set.

CleanShot 2024-09-12 at 19 41 58

CleanShot 2024-09-12 at 19 42 09

robdekort commented 2 months ago

Crickey, you're making me question my sanity. Ok I just did a fresh install: statamic new test.

Screenshot 2024-09-12 at 20 45 11
duncanmcclean commented 2 months ago

I've managed to figure out why this is happening...

The Field::isVisibleOnListing() method checks if a field is display-able on the listing table, by taking the listable config option into account (which defaults to "Hidden by default"):

https://github.com/statamic/cms/blob/6e5d6a20572274c1d71227ea7edda1049c8d1396/src/Fields/Field.php#L220-L227

It checks whether or not listable is null. When it is, it checks the handles, and returns true for fields like title and slug. This is so you always see some columns on a new collection, before you've gone in and customised the blueprint.

This worked fine in Statamic 3 and 4. However, in Statamic 5 we introduced some changes so that default values for fields aren't saved in blueprint YAML files, to try and tidy them up a little.

Because of these changes, it means that if you have listable to "Hidden by default", $this->get('listable') will come back as null, making it think it should show those "default columns".

I'm not sure on the best approach to fix this one. 🤔

Good find though!