Plugin Properties

Last updated on
29 March 2025

Plugins can be customized with various properties.

Properties Overview

hooks

Specifies the hooks this plugin should act upon. Plugins can act on multiple hooks if desired, hence this value being an array. The values here are the same you would replace HOOK with in a hook_preprocess_HOOK function.

Example Values

  • node
  • node__basic_page
  • field
  • page_title
  • region

themes (Module Plugins Only)

Designate which themes this plugin should act on. This is only useful in modules when you want to limit which themes your module plugins affect. Plugins defined in themes only act upon the themes they are defined in.

Values should be the machine names of your themes.

weight

Determines the weight of the plugin, affecting execution order relative to other plugins affecting the same hook.

Works just like weight in other parts of Drupal. The heavier the weight, the later the plugin will run.

Modifying Properties

When configuring your plugin with YAML Discovery, the properties are set within the .preprocessors.yml file.

MY_THEME.preprocessor.node:
  class: '\Drupal\MY_THEME\Plugin\preprocessors\NodePreprocessor'
  hooks:
    - node
  weight: 0

On the other hand, when using Attribute/Annotation-based Plugins, the properties are set within the attribute/annotation.

Help improve this page

Page status: No known problems

You can: