Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

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'}

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
4
Tracked since
Nov 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 4
Maintenance
Dormant

Release Timeline

Releases

Version Type Core 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