Problem/Motivation

Most of the effort in 8.x to "update the theme system" was focused primarily around converting everything to Twig.

While this is all well and good, Twig is ultimately the last step in the "theming" process.

We really didn't touch a lot of the theme system internals, just moved them around a bit into other OO classes/services.

We're still using antiquated hooks to define the theme registry and templates it may provide.

It's time we modernize it using existing systems.

See #2863819-22: Convert theme hooks (defined by hook_theme()) to be objects for more discussion regarding this topic.

Proposed resolution

Modernize the internals of the theme system.

History

There have been quite a few issues/discussions around this topic over the years. The following are a list of related issues for posterity sake:

Plan

Note: some issues can be worked on or implemented independently despite where it lives in its given "phase". This is, currently, just a rough estimation of the current scope of work and its logical progression.

Phase I

Convert current APIs (theme hooks) internals into proper OO code for continued BC support and reliable testability:

Phase II

Replace current APIs (theme hooks) with a modernized theme system:

Phase III

Adding better DX/FX enhancements and utilities:

Phase IV

Finally fixing render arrays of doom:

Comments

lauriii created an issue. See original summary.

lauriii’s picture

This issue was created after a discussion with the @joelpittet and @Cottser in BadCamp.

pixelmord’s picture

This is great! I really appreciate this pragmatic approach to work towards the #components goal in increments, the beauty is that even without that, these steps totally make sense.

cyb_tachyon’s picture

So it looks to me that the next real step for those of us currently using a components theming approach* depends on the following two issues:

But I don't think there's an easy way to get #2809689 into the components module, so we're stuck until 8.3. Still, exciting stuff. It'd be nice to simply add components with a drupal-specific yaml file in their directory and call them in a presenter template with a theme call.

Thanks again @lauriii for putting this together!

* Either using twig include + blocks or twig include + some sort of pre-render

fabianx’s picture

#4: #2809689: Move hook_theme implementations into yml while you can't _move_ things, we could as first step _allow_ to define hook_theme implementations in YML and yes that could start easily within the components module.

So there is not a need to wait for core on that.

dawehner’s picture

Is there a reason this is not in the idea issue queue? Just curious.

lauriii’s picture

@dawehner: Not sure if this belongs there since this is not an idea but instead just a meta issue that explains a vision for this subsystem.

Just quoting the drupal core governance docs:

Subsystem Maintainers
The maintainers of each subsystem are responsible for:
- Communicating the vision for their subsystem.

fabianx’s picture

#6: It is not an idea, but several small concrete actionable issues we have been talking about for years.

At best it belongs to the components initiative (in a way) as it lays some groundwork for it. But components is frozen right now. Also some of this issues are implemented and prototyped in contrib first.

But all the changes / tasks are way within the scope of the theme subsystem, so this should indeed be sufficient.

Also there is no sign-off needed for the whole concept as again this is not a whole initiative, but rather some tasks that make each in themselves sense and are independent.

I feel that is the biggest difference.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pwolanin’s picture

Coming here from another issue - creating render arrays in the Twig template seems like an anti-pattern and I don't even see why we'd support it. Perhaps I'm not understanding the intended feature.

This is less problematic if it's only for specific render elements and the allowed keys can be validated.

What I don't want to support is actually writing render arrays directly as arrays in Twig since we may need to block that to resolve #2860607: Code execution via Twig templates (including inline)

cyb_tachyon’s picture

@pwolanin I think you may be intending to comment on #2818121: Create render array generator that can be used in Twig.

This work is being informed by 2702061: Unify & simplify render & theme system: component-based rendering (enables pattern library, style guides, interface previews, client-side re-rendering) and is attempting to solve the pipeline issues currently present when attempting to integrate a Twig Component library with a Drupal theme and backend.

As I understand it, the plan is to eventually move away from render arrays, and instead focus on experimenting with the "best" ways to get Drupal backend data (which may be organized completely differently from the frontend structure) into a component frontend. For now though, we are building these experiments in Contrib modules on Drupal.org with the idea that a solid implementation will eventually evolve and be ready to include in Drupal 8 Core.

manuel garcia’s picture

Adding related issue for visibility. I a bit confused by the different efforts going on in this area of Drupal...

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markhalliwell’s picture

Title: Theme system improvements roadmap » [meta] Theme System Modernization Initiative
Issue tags: +Theme System Modernization Initiative, +Needs issue summary update

This has stagnated, tremendously.

The IS needs to be updated and reorganized.

markhalliwell’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update
markhalliwell’s picture

Issue summary: View changes
markhalliwell’s picture

Issue summary: View changes
Issue tags: +Needs issue summary update

The IS needs to ultimately be reformatted matching: https://www.drupal.org/core/initiative-proposal-template

I would like to make this an official initiative.

borisson_’s picture

Should we move this issue to the ideas queue to make for easier to coordinate this initiative?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

lauriii’s picture

Issue summary: View changes
lauriii’s picture

Issue summary: View changes

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.