Excluding a bundle without providing a view mode causes a warning

Created on 26 July 2021, almost 4 years ago
Updated 23 July 2025, 3 days ago

Problem/Motivation

When excluding an entity type (or bundle) and not providing a view mode in the service definition, the following warning is thrown:

Warning: Undefined array key "view_mode" in Drupal\entity_preprocess_services\EntityPreprocessServicesManager->serviceDefinitionMatches() (line 122 of modules/contrib/entity_preprocess_services/src/EntityPreprocessServicesManager.php).

Steps to reproduce

Create a service and definition excluding a complete bundle.
Example:

  my_module.preprocess.node.teaser:
    class: Drupal\my_module\PreprocessService\NodeTeaserPreprocessService
    tags:
      - { name: entity_preprocess_service, priority: 200 }
    properties:
      applies_to:
        - { entity_type: 'node', view_mode: 'teaser' }
      excludes:
        - { entity_type: 'node',  bundle: 'news' }

Proposed resolution

A small fix needs to be applied to the "EntityPreprocessServicesManager" so it can correctly exclude entities without view mode or bundle.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇧🇪Belgium wtrv

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024