Problem/Motivation
#1367354: The list of theme hook suggestions for "field" is incorrectly ordered and has namespacing collisions is a pre-existing issue with field template suggestions.
#2808481: Introduce generic entity template with standard preprocess and theme suggestions is a new issue adding generic entity template suggestions that could run into the same issue.
We need to figure out whether to namespace suggestions (i.e. bundle-$suggestion or b-$suggestion) and which format to use to prevent the potential for conflicts. This would also allow the targeting of the template to be figured out from the filename rather than just the logic in the theme registry building.
Comments
Comment #2
berdirCross-posting from #2808481-62: Introduce generic entity template with standard preprocess and theme suggestions
Comment #3
tstoecklerSo the beef I have with
b)orc)(or in other words with the reasoning behind this issue) - regardless of the actual experience for themers - is that it would be introducing a one-off for entity templates. There are, however, numerous template suggestions which can conflict, and which currently suffer from the same issue. So not only would we be introducing an inconcistency between current entity templates (node, user, ...) and the new generic entity template - which I think is acceptable as the former can be seen as the deprecated BC-layer of the latter - but we would be introducing an inconcistency between the generic entity template and every other template.Other conflicts we currently have:
block__$provider/block__$base_plugin_id/block__$derivative_plugin_id/block__$idfield__$field_type/field__$field_namefield__$entity_type_id__$bundle/field__$entity_type_id__$field_nameAnd this is just in core. I didn't check but I am sure that there are more in the world of other uber-generic modules like Panels / Display Suite / Layout Plugin / Search API / ...
Comment #4
fabianx commentedHowever those should be changed by adding new suggestions for those as well and deprecate the old suggestions.
The theming community in #twig (slack) overall (though it was a non-representative poll) was for long and descriptive names by a large margin.
Only a few for the shortened names and only another few for keeping the old convention with conflicts.
Comment #5
catchThe issue title already mentions field templates - I think we should come up with a pattern here and apply it elsewhere as Fabianx says.
Comment #6
markhalliwellThis was only asked once and getting a few people's opinion who were in that room really doesn't indicate a "large margin".
---
That being said, I am in favor of explicitly long suggestions, only if template discovery was altered to also allow these suggestions to be broken up into folders (as was semi-depicted in #2808481-56: Introduce generic entity template with standard preprocess and theme suggestions).
---
After thinking about the above (folder) comment a bit more, I think the easiest solution would be to allow a 1:1 mapping of
__to a directory separator (/):node__bundle_foo__view_mode_bar__1234Would become:
And, if not found, would search for the original long ass filename (for BC and themers who "like" these.......):
This gives the ability to dramatically reduce the length of a filename from
node--bundle-foo--view-mode-bar--1234.html.twigto simply1234.html.twig.Moving forward, I think simply adding directory detection is a good enough compromise to support these ever growing theme hook suggestions.
Comment #7
rainbowarrayI would definitely like to avoid using directories as a way to shorten file names. Being able to place templates in directories of my choosing is important to me when working on a theme.
My preferences would be as follows:
Full prefixes but long file names > Abbreviated prefixes and slightly longer file names > Current system where conflicts happen because of lack of prefixes > Directory structure required for template suggestions
Comment #8
markhalliwellWhy? This sounds more like personal preference than a logical dispute. We get it, you don't like directories or rather you like naming them arbitrarily. That's fine.
My suggestion above still allows filenames to be 10 miles long if you really want them to be and place them wherever you want.
If this kind of directory support isn't included, however, then y'all are forcing us to use these long winded names.
That's unacceptable.
This simply gives very complex themes (that have many, many templates) the ability to have a folder structure that makes sense.
It's very similar to PHP's PSR autoloading, if you will.
Comment #9
rainbowarrayI wouldn't mind if directories are an option if people want to make use of that. If I can have long file names and others can have short file names with directories, that would be cool.
Organizing templates by component is useful. Often it takes multiple templates of different types to get all the templates for a particular component.
Comment #10
SlayJay commentedas much as I dislike the folder idea, it is consistent with the rest of drupal 8.
If I want to make a new entity type I have to put it in an Entity folder in my module.
Having to put entity templates in an Entity folder in my module or theme seems like the most consistent / least confusing method.
It's a pain in the ass, especially if you're used to putting theme files in your own folder structures (I am)... but it was also a pain in the ass for module developers to have to start putting files into folders as well, and we got over it :P
Comment #12
manuel garcia commentedMarked #2881195: Duplicate template suggestions as duplicate.
Comment #19
krzysztof domańskiComment #23
darvanenTriaged as part of the Bug Smash Initiative.
Closing as duplicate of #1367354: The list of theme hook suggestions for "field" is incorrectly ordered and has namespacing collisions.
If that is wrong, please reopen by setting to 'Active' and add a comment explaining why.
Comment #24
berdir4 years later...
I think this is not a duplicate, but the meta issue of that or maybe better, a policy issue on whether or not we should do prefixes, it also references the entity issue that was essentially blocked on this.
I did make a specific proposal with a few questions in #2752443: Incorrect order and duplicate theme hook suggestions and would appreciate feedback there, but I think this is still an issue that should have its own resolution on whether or not we use prefixes or not, and if all entries should use prefixes or only less common ones, likely guided by the specific examples in the field issue.
Comment #25
catch#3566261: [regression] custom field twig for second comment fields has null value in comment after 11.3.0 upgrade just ran into this. We could use an issue summary update here.
@berdir I can't see a comment from you on #2752443: Incorrect order and duplicate theme hook suggestions, should that be a different issue link?
Comment #26
berdirI meant to link to #1367354: The list of theme hook suggestions for "field" is incorrectly ordered and has namespacing collisions I think.