Alter Entity View Mode - Forced page title

Created on 28 May 2025, 6 days ago

Problem/Motivation

When we use event "Alter view Mode" it displays page title. So in case that there is by default "page title" block enabled now see your page title twice and no possible to hide it (just disable block currently).

1.Create any Article
2.Visit the page - 1 title is visible taken from the block "page title"

3.Use ECA to display Teaser so event "Alter view Mode" > "Entity: Set View Mode" and use for example "teaser"
4.Enable ECA and navigate back to visit page (Clear cache if needed):

You can find attached ECA model to test article.
I have used different view modes and different themes but with the same result.

Does anyone know why there is a page title (h2) forced and displayed?

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΈπŸ‡°Slovakia coaston

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

Comments & Activities

  • Issue created by @coaston
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    This is either an issue with the view mode you're setting, i.e. if that also contains the title, but the default view mode doesn't, then that's where the difference comes from.

    What ECA does with your model is just responding to Drupal core's hook_entity_view_mode_alter(). Everything else is down to default Drupal functionality and configuration of your site.

  • πŸ‡ΈπŸ‡°Slovakia coaston

    Hm...even I change from "teaser" to "default" view mode in "Entity:set view mode" it is the same.

    Actually i wanted condition if customer is X then teaser and if negate condition use default.
    -title is displayed in both cases.

    But of course I have tested with a simple model where there is not any condition but if I choose "default" there is the same behaviour.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Then this must be a core bug. Because what's happening here, if it were implemented in PHP, is this:

    /**
     * Implements hook_entity_view_mode_alter().
     */
    function eca_content_entity_view_mode_alter(string &$view_mode, EntityInterface $entity): void {
      $view_mode = 'teaser';
    }
    

    If that causes Drupal to render the entity with a title, then that's an issue in core.

  • πŸ‡ΈπŸ‡°Slovakia coaston

    Thank you,

    I have tested your code with a custom module and I have disabled "My eca model" and now when custom module force teaser or any other view mode (including the default one" i can see title twice. So it seems you were right it is not eca related.

    Not sure what now:)

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Thank you @coaston for taking the time to test this explicitly. What's required next is a bug report in the Drupal core issue queue. Don't be afraid, just describe what the problem is, maybe on the level of your manual test only because that demonstrates that it's definitely a core issue. Providing the steps on how to reproduce it will help a lot. Maybe you can then link that new issue here so that folks from here can follow along what's happening there.

  • πŸ‡ΈπŸ‡°Slovakia coaston

    Thank you.

    I have raised drupal core issue πŸ› View Mode renders Title Active

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Thanks for creating the other issue. closing this as works as designed.

Production build 0.71.5 2024