Problem/Motivation
As stated in the parent issue #3050389: [META] Remove dependency to Classy from core themes, Classy will be moved to contrib before Drupal 9 and we have to remove dependencies on Classy from all core themes.
This process included documenting template usage in this spreadsheet:Core Theme's use of Classy. This documenting made it apparent that there are 24 templates in Classy that are identical to the same-named templates in Stable. This means it is not necessary to provide Classy-dependent themes with copies of these templates, as an identical template will be loaded from Stable if Classy is not available.
Running diff -srq classy/ stable/ | grep identical shows that these templates are identical:
Files classy/templates/content-edit/file-upload-help.html.twig and stable/templates/content-edit/file-upload-help.html.twig are identical
Files classy/templates/content-edit/file-widget-multiple.html.twig and stable/templates/content-edit/file-widget-multiple.html.twig are identical
Files classy/templates/field/image-style.html.twig and stable/templates/field/image-style.html.twig are identical
Files classy/templates/form/checkboxes.html.twig and stable/templates/form/checkboxes.html.twig are identical
Files classy/templates/form/confirm-form.html.twig and stable/templates/form/confirm-form.html.twig are identical
Files classy/templates/form/container.html.twig and stable/templates/form/container.html.twig are identical
Files classy/templates/form/dropbutton-wrapper.html.twig and stable/templates/form/dropbutton-wrapper.html.twig are identical
Files classy/templates/form/form-element-label.html.twig and stable/templates/form/form-element-label.html.twig are identical
Files classy/templates/form/form.html.twig and stable/templates/form/form.html.twig are identical
Files classy/templates/form/input.html.twig and stable/templates/form/input.html.twig are identical
Files classy/templates/navigation/links.html.twig and stable/templates/navigation/links.html.twig are identical
Files classy/templates/navigation/menu-local-action.html.twig and stable/templates/navigation/menu-local-action.html.twig are identical
Files classy/templates/navigation/pager.html.twig and stable/templates/navigation/pager.html.twig are identical
Files classy/templates/navigation/vertical-tabs.html.twig and stable/templates/navigation/vertical-tabs.html.twig are identical
Files classy/templates/views/views-view-grid.html.twig and stable/templates/views/views-view-grid.html.twig are identical
Files classy/templates/views/views-view-list.html.twig and stable/templates/views/views-view-list.html.twig are identical
Files classy/templates/views/views-view-mapping-test.html.twig and stable/templates/views/views-view-mapping-test.html.twig are identical
Files classy/templates/views/views-view-opml.html.twig and stable/templates/views/views-view-opml.html.twig are identical
Files classy/templates/views/views-view-row-opml.html.twig and stable/templates/views/views-view-row-opml.html.twig are identical
Files classy/templates/views/views-view-rss.html.twig and stable/templates/views/views-view-rss.html.twig are identical
Files classy/templates/views/views-view-unformatted.html.twig and stable/templates/views/views-view-unformatted.html.twig are identical
There are 3 additional templates that should be added to this list as they should be identical.
classy/templates/field/image-formatter.html.twig: the only difference a line in Classy's DocBlock that should have been removed in #2350837: Convert most usages of EntityInterface::getSystemPath() to use routes.
classy/templates/form/select.html.twig: the only difference are annotation changes that should have been applied to Stable in #2546248: Use consistent style to mention HTML tags in code comments, but were only applied to Classy.
classy/templates/form/field-multiple-value-form.html.twig: the version in stable had a line of whitespace following the DocBlock that was not present in Classy's
Proposed resolution
Address the differences in the 3 almost-identical templates listed in Problem/Motivation
Add a test that confirms these templates are truly identical, and as a result do not need to be included in the template copying efforts necessary to decouple themes from Classy.
Remaining tasks
Implement, review.
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Release notes snippet
n/a
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | interdiff.3098150.13-17.txt | 4.26 KB | longwave |
| #17 | 3098150-17.patch | 4.15 KB | longwave |
| #13 | 3098150-13.patch | 4.24 KB | bnjmnm |
| #13 | interdiff_7-13.txt | 15.03 KB | bnjmnm |
| #7 | 3098150-7.patch | 16.6 KB | bnjmnm |
Comments
Comment #2
bnjmnmComment #3
bnjmnmThis patch
{% extends %}in Claro to call@stable/instead of@classy/Comment #4
lauriiiThis change gives a hint that this might cause a BC break. Technically, we should deprecate template instances first before removing them but I'm afraid we don't have process for that.
Comment #5
bnjmnmIs the concern in #4 (1)-> specific to the
{% extends %}in form-element-label.html.twig, or (2) ->about removing these files in general? I believe it's (1) based on my recollection of a discussion from a few weeks ago.If that recollection is correct, I can remove that file and address it in a followup regarding how to address the 6 includes/extends of Classy templates in other core themes. (the other 5 are for Classy templates that are not identical to Stable)
If there are concerns about removing the files overall (which certainly seems like a warranted concern), this could be addressed by either copying those same-as-stable files to the core themes with all the diffrerent-from-stable copies - or another possibility is overriding Twig's token parsers to re-route requests to the deleted @Classy templates to stable, only when it's an identical file. This could also trigger a deprecation notice. This can be done fairly easily for includes, but extends is may be tricker because ExtendsTokenParser is marked @final in Twig 1 and is defined as
final classin Twig 2.Comment #6
bnjmnmI found a potential way around the BC concerns regarding any extends or includes to @classy templates. This is accomplished by using a Twig node visitor. If a theme requests an @classy template that has an identical version in Stable, the node visitor will retrieve Stable's instead. This would mean that it's still possible to request @classy templates even if they're removed, this would only be applied to template that are identical in Stable, so there's no difference to the user, it's just loaded from a different theme. A patch with this will show up shortly. I'm also seeing if it's possible to incorporate template deprecation errors with this approach. Not sure yet about that part
Comment #7
bnjmnmThis patch reverts
In favor of using a node visitor that changes requests to identical-to-stable @classy templates to request it from @stable instead.
A failing version of the patch without the node visitor running is provided to demonstrate that the node visitor is successfully retrieving the Stable template even if @classy is requested.
An additional version of the patch, which will also have many fails, was added to demonstrate that the node visitor could potentially be the home for Classy template deprecation warnings.
Comment #10
lauriiiI'm wondering if it's a good tradeoff to add this type of additional logic to our Twig integration given that the only benefit is not having duplicate templates between Stable and Classy. Could we instead mark them as special case templates in the tests?
Comment #11
bnjmnmI'd be interested in hearing more about how marking them as special case templates could work. I thought removing these from Classy was recommended/agreed upon during a discussion outside of this issue, but it's not the only approach I had in mind. The biggest thing I'd like to avoid is having to provide Classy-inheriting themes with their own copies of these templates. Doing that will require 88 additional manual reviews+screenshots to the efforts.
Another way to avoid copying these identical-to-Stable templates to each theme is to change the approach in #7 a bit:
classy/templates/field/image-formatter.html.twig,classy/templates/form/select.html.twig,classy/templates/form/field-multiple-value-form.html.twigthat make the should-be-identical-to-Stable templates identical.Interested in thoughts regarding that approach vs. the one in #7 + if there are other ways to avoid the 88 template-copies + perhaps the 88 copies should happen (even though I'd rather they didn't)?
Comment #12
lauriiiI'm sorry for the confusing input I gave prior to this. I do still think that it would be desirable to get rid of the duplicates, but not at any cost. The fact that we have to make changes to our Twig integration made me reconsider whether removing the duplicates would prove enough value to justify that.
I think your proposed plan works, let's move forward with that 👍
Comment #13
bnjmnmThis change sounds good to me - less disruptive while still eliminating the need to copy a bunch of unnecessary templates. Added a note to change #3096349: Create test for confirming Themes do not depend on Classy templates to reflect this approach once this issue lands.
Comment #14
lauriiiLooks good 👍Has essentially the same impact without minimal change to production code. Thank you! 👏
Comment #15
longwaveThis could be a data provider which passes each template as an argument to the test method.
We could use assertFileExists()?
Comment #16
lauriiiIt seems like we should address #15 one way or another. I'm not sure if we want to do #15.1 but #15.2 seems like something that we should potentially do.
Comment #17
longwaveFixed both items in #15
Comment #18
lauriiiThank you 👍
Comment #19
longwaveShould we retitle this issue, as we are no longer actually removing anything?
Comment #20
lauriiiComment #21
bnjmnmUpdated IS to reflect that the Classy templates are not being removed as originally planned.
Comment #22
alexpottCommitted and pushed 92e8b7b66a to 9.0.x and e6d6b85ec9 to 8.9.x. Thanks!
We need to make this change anyway - right? I guess that can be in a follow-up