Skip to main content
Home
Drupal life hacks

Main navigation

  • Drupal
  • React
  • WP
  • Contact
  • About
User account menu
  • Log in

Breadcrumb

  1. Home

Deprecation Alert: theme_file in Views Plugins Is Going Away in Drupal 12

By admin, 7 October, 2025

Introduced in Drupal 11.3.0

Drupal core continues its modernization journey, and one of the latest updates affects how Views plugins define their template preprocess functions.
If your Views plugin currently uses the theme_file key in its plugin definition — it’s time to update your code.


🔍 What Has Changed

In previous Drupal versions, Views plugins could include a key like this in their plugin annotation:

theme_file = "my_module.theme.inc"

This file would contain preprocess functions such as:

function template_preprocess_views_view_field__my_plugin(&$variables) {
  // Prepare data for the template.
}

The theme_file mechanism told Drupal where to find those functions.

Starting from Drupal 11.3.0, this approach is deprecated and will be completely removed in Drupal 12.0.


💡 Why It Was Deprecated

The Drupal team has streamlined how preprocess functions are registered.
Today, all preprocess callbacks are expected to be explicitly registered via hook_theme() or defined directly in object-oriented (OOP) preprocess methods within the plugin class itself.

This change brings consistency across the system and reduces the number of “magical” lookups that Drupal used to perform behind the scenes.


🧭 How to Update Your Code

You have two options for modernizing your Views plugins:


Option 1: Minimal Fix (Move to .module File)

You can simply move your existing preprocess functions from the old *.theme.inc file into your main module file:

function my_module_preprocess_views_view_field__my_plugin(&$variables) {
  // Prepare your data here.
}

As long as the corresponding theme hook is registered, Drupal will automatically discover this function.


Option 2: Recommended Fix (OOP Preprocess Method)

The preferred modern approach is to define a preprocess() method directly inside your plugin class:

namespace Drupal\my_module\Plugin\views\field;

use Drupal\views\Plugin\views\field\FieldPluginBase;

/
 * Provides a custom field plugin.
 *
 * @ViewsField("my_plugin")
 */
class MyPlugin extends FieldPluginBase {

  /
   * Preprocesses template variables for this plugin.
   */
  public function preprocess(array &$variables) {
    // Your preprocessing logic here.
  }

}

This object-oriented style makes the plugin self-contained, easier to read, and more consistent with how Drupal handles templates in general.


🧱 Summary

Old behaviorNew behavior
theme_file = "..." in plugin annotationDeprecated
Preprocess functions in .theme.incDeprecated
Preprocess functions in .moduleStill valid
preprocess() method in the plugin classRecommended

🚀 Final Thoughts

If your module defines custom Views plugins, check them for theme_file usage now.
Removing it is a simple change, but keeping your codebase aligned with Drupal’s evolving standards ensures smoother upgrades — and fewer surprises when Drupal 12 arrives.

Tags

  • #Drupal Planet

Comments

About text formats

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Powered by Drupal