This is blocked by #2869859: [PP-1] Refactor theme hooks/registry into plugin managers.

Problem/Motivation

All changes to $variables that will be printed in templates currently happen in the same place, preprocess. Things that happen in preprocess include both creating initial variables and then altering those variables later.

Proposed resolution

Use a standard hook naming convention, exactly like the FAPI does. These standardized hooks would allow the theme system's phases to be split into a more systemic and easier to understand process. This issue is a meta for moving all the things we are currently doing in preprocess into their appropriate places.

Remaining tasks

  • @todo

User interface changes

None.

API changes

Deprecate hook_preprocess().

#2035055: Introduce hook_theme_prepare[_alter]() and remove hook_preprocess_HOOK()

Comments

markhalliwell’s picture

Assigned: Unassigned » markhalliwell

I'll spearhead this once prepare is in.

markhalliwell’s picture

Title: [META] Migrate all core preprocess functions to utilize the new prepare phases instead, and Deprecate hook_preprocess(). » [META] Migrate all hook_preprocess() functions to hook_theme_prepare()

Cleaner title, moving the "deprecation" of hook_preprocess() to #2035055: Introduce hook_theme_prepare[_alter]() and remove hook_preprocess_HOOK()

star-szr’s picture

Version: 8.0.x-dev » 9.x-dev
Issue summary: View changes
catch’s picture

Version: 9.x-dev » 8.1.x-dev
Status: Active » Postponed

Moved #2035055: Introduce hook_theme_prepare[_alter]() and remove hook_preprocess_HOOK() back to 8.x since I think it's worth exploring bc layers for it.

If we did that, then conversions could also happen against 8.x.

joelpittet’s picture

Assigned: markhalliwell » Unassigned

Other than a a name change, what would be gained from changing the hook name? I agree the name is better but people from D7 know hook_preprocess()

I think it would be maybe worth looking into something other than hooks for this. Maybe some kind of alter plugin or event so we can "stop propagation", change priority/weights, or fancy things like that.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.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.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.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.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.

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.

joelpittet’s picture

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

I don't think the name change is worth the BC layer. I may be missing something, but what do we gain?

andypost’s picture

Probably this could be closed

markhalliwell’s picture

Title: [META] Migrate all hook_preprocess() functions to hook_theme_prepare() » [META] Migrate hook_preprocess() functions to template plugin prepare() methods
Version: 9.x-dev » 8.8.x-dev
Issue summary: View changes
Issue tags: +Theme System Modernization Initiative, +Needs issue summary update
Parent issue: » #2869859: [PP-1] Refactor theme hooks/registry into plugin managers

Actually, this still needs to happen... although the direction has changed a bit (more OO).

I suppose we can just repurpose this for actually migrating all of core once #2869859: [PP-1] Refactor theme hooks/registry into plugin managers is actually implemented.

These will both be big tasks and should likely be separate issues anyway.

I still like the name change from "preprocess" to "prepare" though, so we can use that as the new template plugin method name.

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.