Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Entity Preprocess Services

Security covered Maintenance fixes only 116 sites

Part of the Entity ecosystem · 308 projects

This module allows developers to integrate custom services into entity pre-processing. It provides a framework for defining services that can be automatically triggered during the rendering process for specific entity types, bundles, and view modes, with built-in support for nodes and paragraphs.

This module provides a way to use services when preprocess entities.
It does this by adding a service pass and provider.

It is built for developers and doesn't add any special functionality
out of the box.

The module will however be able to call services out of the box for nodes and paragraphs.
But can easily be used for all entities.

You just have to call the following function:
_entity_preprocess_services_preprocess_entity

See configuration on how to use this.

CONFIGURATION

-------------
You can add preprocess services for nodes and paragraphs out of the box.
A preprocess service will be picked up by "tagging" it.

See example module file on how this works:
entity_preprocess_services_example.services.yml

You tag a service as a "preprocess service" by adding this to your service:

tags:
  - { name: entity_preprocess_service, priority: 100 }

Priority can be used to establish the order of preprocess services.

You can then specify for which entities this service must be called.
You do this by adding following to your service:

properties:
      applies_to:
        - { entity_type: 'node', view_mode: 'full'}

There are 3 properties that can be added:
- entity_type: type of entity (getEntityTypeId())
- bundle: for what bundle? (bundle())
- view_mode: for what view mode?

A full service would look like this:

entity_preprocess_services_example.preprocess_service.node.full:
class: Drupal\entity_preprocess_services_example\PreprocessService\ExampleNodeFullPreprocessService
tags:
  - { name: entity_preprocess_service, priority: 100 }
properties:
  applies_to:
    - { entity_type: 'node', view_mode: 'full', bundle: 'page'}

This service will call the preprocess function for nodes of type page in
the full view mode.

Out of the box, it only works for nodes and paragraphs.
However, you can quickly use this for other / entities or custom entities.

Simply call the function: _entity_preprocess_services_preprocess_entity

Pass 3 arguments:
- the variables array
- the entity
- the view mode

The function will do the rest.

/**
 * Implements hook_preprocess_paragraph().
 */
function entity_preprocess_services_preprocess_paragraph(array &$variables) {
  /** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
  $paragraph = $variables['paragraph'];

  _entity_preprocess_services_preprocess_entity(
    $variables,
    $paragraph,
    $variables['elements']['#view_mode']
  );
}

EXCLUDING ENTITIES

----------
It's possible to exclude certain entity types from a service.
You can do this with the "excludes" key under properties.

For example, you want to preprocess all nodes except "news teasers".
Your service definition can look as follows:

entity_preprocess_services_example.preprocess_service.node.full:
class: Drupal\entity_preprocess_services_example\
PreprocessService\ExampleNodeFullPreprocessService
tags:
  - { name: entity_preprocess_service, priority: 100 }
properties:
  applies_to:
    - { entity_type: 'node', view_mode: 'full'}
  excludes:
   -  { entity_type: 'node',  bundle: 'news'}
Drupal 8–11

Ask your assistant about Entity Preprocess Services

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
6
Tracked since
Mar 2023
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 4
Maintenance
Slowing

Release Timeline

Releases

Version Type Core PHP Release date
3.0.4 Stable 8–11 Jul 24, 2025
3.0.x-dev Dev 8–11 Jul 24, 2025
3.0.3 Stable 8–11 Jul 17, 2025
3.0.2 Stable 8–11 Nov 8, 2024
3.0.1 Stable 8–10 PHP >=8.1 Mar 18, 2024
3.0.0 Stable 8–10 PHP >=8.1 Mar 8, 2023