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]: Entry Type Names have to be unique #14774

Closed
sandrodunkel opened this issue Apr 9, 2024 · 7 comments
Closed

[5.x]: Entry Type Names have to be unique #14774

sandrodunkel opened this issue Apr 9, 2024 · 7 comments
Labels

Comments

@sandrodunkel
Copy link

What happened?

Description

Why can't two Entry Types have the same name? It's very likely to have for example two Entry Types called Text, that need to be very different for their respective use in different matrixes. I expect the handle to be a unique identifier and the entry type to be "visual" only, therefore allowing there to be several Entry Types with the same name.

Steps to reproduce

  1. Create Entry Type called Text to use in Matrix ABC.
  2. Create another Entry Type called Text that has a very different field layout to use in Matrix XYZ.

Expected behavior

The two Entry Types can co-exist, even though they have the same name. The handle serves as a unique identifier.

Actual behavior

Entry Type cannot be saved due to an error:

Name "Text" has already been taken.

Craft CMS version

5.0.0

PHP version

8.2.15

Operating system and version

MacOS Sonoma 14.1.1

Database type and version

MySQL 8.0.33

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

  • Batch Actions (2.0.0)
  • CKEditor (4.0.2)
  • Control Panel CSS (3.0.0)
  • SEOmatic (5.0.0-beta.8)
@brandonkelly
Copy link
Member

If two entry types had the same name, it would not be clear which one was which in entry type selection inputs, such as sections’, Matrix fields’, and CKEditor fields’ “Entry Types” settings.

That said, you can technically pull it off using static translations.

Create a translations/en/site.php file (or whatever language code your authors will actually be using), with a mapping of actual entry type names to their author-facing names:

<?php

return [
    'Text (Simple)' => 'Text',
    'Text (Advanced)' => 'Text',
];

Note that this will also impact admins, so if you go this route, you’re going to want to set an icon and/or color on the entry types as well, so you have some way of identifying which is which when setting up your sections and Matrix/CKEditor fields.

@sandrodunkel
Copy link
Author

Thanks, Brandon, for our quick explanation. Whilst I get your point I feel like that's the problem of us devs how to handle this (different Icon, different Color, temporarily rename one of them, etc.). Because as you described, the workaround using static translations leads to the exact same result as letting me being able to give them the same name in the first place. In other words: you're letting me do this using extra steps, only making my life harder.

The whole point of a CMS is that a client is able to have an awesome experience managing their website's content (which they absolutely do with Craft). But the resulting matrix blocks named Text 1, Text 2, Text 3 just seem unprofessional.

Nevertheless, thanks for explaining the workaround using static translations. I will definitely use this.

@brandonkelly
Copy link
Member

In other words: you're letting me do this using extra steps, only making my life harder.

Yes, because in general it would not be a good idea to do this. So that’s a way of “encouraging” what we feel is a better practice.

That said, we might consider making it possible to relabel entry types at the section/Matrix/CKEditor level, like how fields can be relabeled within a field layout. (#14779)

@sandrodunkel
Copy link
Author

+1, might be a great addition!
Thanks, Brandon.

@Mathias-Syversen
Copy link

+1 to this.
Should be up to the developer to handle naming and prevent multiple entry types with the same name in the same context.
Field naming dont have this artificial restriction, and the chances are much higher you get duplicates with them, I'd say.

@brandonkelly
Copy link
Member

Field naming dont have this artificial restriction, and the chances are much higher you get duplicates with them, I'd say.

That’s a good point @Mathias-Syversen.

Change of heart, decided to go ahead remove the unique restriction on entry type names for Craft 5.3. (#15438)

@brandonkelly
Copy link
Member

Craft 5.3.0-beta.1 is out with support for duplicate entry type names 🎉 (#15438)

We’re targeting August 6 for the GA release. If you’d like to test ahead of time, change your craftcms/cms requirement in composer.json to:

"craftcms/cms": "^5.3.0-beta.1",

and then run composer update.

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

No branches or pull requests

3 participants