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

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

Open
robdekort opened this issue Sep 12, 2024 · 5 comments

Comments

@robdekort
Copy link
Contributor

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
Copy link
Member

Do you have any preferences set?

@robdekort
Copy link
Contributor Author

Nope! Can't reproduce it then?

@duncanmcclean
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
Member

duncanmcclean commented Sep 13, 2024

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"):

cms/src/Fields/Field.php

Lines 220 to 227 in 6e5d6a2

public function isVisibleOnListing()
{
if (is_null($this->get('listable'))) {
return in_array($this->handle, ['title', 'slug', 'date', 'author']);
}
return ! in_array($this->get('listable'), [false, 'hidden'], true);
}

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants