Views field labels cannot be defined per view (display)

Created on 22 November 2024, about 1 month ago

Problem/Motivation

When you change the label of a field which also exists in other views, the label is changed everywhere and not just in the view you did the change. This is not acceptable as the same entity field (of different entity types) can have different meanings, for example the created field of an entity. For nodes it has the meaning content "created at", while for group memberships it has the meaning of the user being a group "member since" (where the part inside the "" should be the label).

This especially affects views displayed as table in the non-admin theme when available space is limited due to the design and you want to display two or more fields in a single column and need to change the field label to display the meanings of both/all fields in that column. (BTW this is another use case for Allow HTML in views field labels Active to allow <br> inside the view label.)

Steps to reproduce

  1. Setup a fresh Drupal site using the Standard profile.
  2. Install the group module .
  3. Enable the media module (no further configuration needed, just to have its views there)
  4. Create a group type and a single group of that type.
  5. Change the views.view.group_members view
    1. Ensure that it contains both the "created" and "changed" fields in this order (other fields don't matter).
    2. Change the table display settings to display the "changed" field inside the "created" column, delimited by a <br>.
    3. Change the label of the "created" field to Created<br>Member since (the line break will not work, see Allow HTML in views field labels Active ) or Created / Member since.
    4. Change the label of the "changed" field to Member since.
    5. Save the view.
  6. Display other views like views.view.content or views.view.media and check the table header of the merged columns.
  7. Export configuration and check the exported labels of the changed fields.

In my site, the nodes and media entities were not "Created at" but "Member since" after this, which obviously makes no sense.

Proposed resolution

Ensure that such changes are per view display and do not affect other displays of the same view (except when the changes are in the default display) or other views.
For localization (config translations) provide the combined view and view display ID as translation context.

Release notes snippet

Probably this needs a release note to make developers and site admins aware of this change.

🐛 Bug report
Status

Active

Version

10.3

Component

views.module

Created by

🇦🇹Austria mvonfrie

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

Comments & Activities

  • Issue created by @mvonfrie
  • Can we get simpler steps to reproduce, ideally with only the default modules in a standard install?

  • 🇳🇿New Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

  • Why is this a bug and not a feature request?

  • 🇦🇹Austria mvonfrie

    @cilefen, for simpler steps just skip installing the group modile and modify the views.view.media view in a similar manner.

    Why is this a bug and not a feature request?

    Because when I change one view (or a config entity in general) I don't expect another virw config entity to be modified with the same change. And there are even cases where having different labels (or other values) for the same field on different displays are needed, i. e. a table display with abbreviations for column labels vs. full name for a grid display.

    And why is a translation context needed?

    Because otherwise all translations with the same value will get changed. The group module's group members view doesn't show insider scoped roles as user inherits from a global Drupal role he has but just manually assigned group roles (there's an issue for that, no need to discuss it here). To circumvent this until a fix is available I've added a column with the (global) Drupal roles and changed the label translation (German) of the other column to "Gruppen-Rollen". Then I noticed that the page title of admin/people/roles changed to "Gruppen-Rollen" as well.

  • 🇦🇹Austria mvonfrie

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

    Of course, but in my opinion it still makes sense to report the version I observed it and then you change it as needed. Maybe due to other changes the problem doesn't exist anymore in 11.x.

  • The issue summary needs to be updated with the "steps to reproduce" changes that @mvonfrie verified.

Production build 0.71.5 2024