Allow plurals on bundle labels

Created on 12 July 2016, about 9 years ago
Updated 25 June 2023, about 2 years ago

Problem/Motivation

Entity types can define now plurals for their labels starting with #1850080: Entity type labels lack plurality, cannot generate UI text based on label if plural is needed . It's possible now to have the variants "content item" (singular) and "content items" (plural) for nodes. We want the same for bundles. We want to be able to have "article" (singular) and "articles" (plural).

It's not the same as for entity types. Entity types can define the label plural variants in the annotation while for bundles the site builder should be able to add such variants. Thus we need to store the variants in the bundle config entity and provide UI for site builders.

Proposed resolution

Create the foundation that allows bundle config entities to store plural labels and add this ability to the node_type bundle entity as a start.

  1. Create a new interface EntityBundleWithPluralLabelsInterface that defines 6 new methods:
    • setSingularLabel()
    • getSingularLabel()
    • setPluralLabel()
    • getPluralLabel()
    • setCountLabel()
    • getCountLabel()

    These are similar to those implemented to entity types.

  2. Add a common implementation for the new 6 methods in a new trait EntityBundleWithPluralLabelsTrait, to be reused in most of the bundle config entities.
  3. Create a bundle_entity_with_plural_labels schema to be used by bundles that want to support plural labels. The new schema contains the new storage keys: label_singular, label_plural, label_count.
  4. Allow more than one version for the count label. This is because, in the real world, a site might need different versions depending on the place these count labels are used. Let's see a hypothetical website scenario:
    • On a page the count label could be a simple label as 1 article\x03@count articles.
    • On a search results page we need a different version: 1 article was found\x03@count articles were found. Note that we cannot build this version by deriving from the first one because of the was/were thing.
    • In other place something like <span>1</span> article\x03<span>@count</span> articles.
    • In a 3rd place, because the count is displayed in other <div ...> or even is rendered in a different theme hook, just Article\x03Articles, without the count part.

    Similar with translated strings, were we are able to store contextualised translations and then retrieve them by passing the context identifier, we allow label_count to store multiple versions, identifiable by a context string identifier.

  5. Bundles declared via hook_entity_bundle_info(), are able to declare such labels by using the keys: label_singular, label_plural and label_count. This will be documented in entity.api.php [see #108, #109].
  6. Bundles supporting plurals labels, regardless if they are defined as config entities or via hook_entity_bundle_info(), are able to process the count label, given a count, by using the new service method entity_type.bundle.info::getBundleCountLabel(). This is a new method exposed by EntityTypeBundleInfoInterface [see #108, #109]
  7. Make NodeTypeInterface extend also EntityBundleWithPluralLabelsInterface.
  8. Make NodeType use the EntityBundleWithPluralLabelsTrait trait.
  9. Make node.type.* schema extend bundle_entity_with_plural_labels.
  10. Add plural labels to all node types shipped with Drupal core.
  11. The UI for editing node type plural labels is added in a follow-up: #2938251: Allow edit of bundle plural labels in the node type form .

Remaining tasks

User interface changes

None. The UI changes are split in #2938251: Allow edit of bundle plural labels in the node type form .

API changes

New interface \Drupal\Core\Config\Entity\EntityBundleWithPluralLabelsInterface:

  • setSingularLabel()
  • getSingularLabel()
  • setPluralLabel()
  • getPluralLabel()
  • setCountLabel()
  • getCountLabel()

Data model changes

The node type bundle config entity has new keys/values: label_singular, label_plural, label_count.

Feature request
Status

Needs work

Version

11.0 🔥

Component
Entity 

Last updated 9 days ago

Created by

🇷🇴Romania claudiu.cristea Arad 🇷🇴

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • Merge request !4252[11.x] Plural bundle labels → (Open) created by claudiu.cristea
  • last update about 2 years ago
    29,474 pass, 3 fail
  • Pipeline finished with Failed
    over 1 year ago
    #65496
  • Pipeline finished with Failed
    over 1 year ago
    Total: 784s
    #65498
  • Status changed to Postponed over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Despite this being blocked, I think this can already be reviewed. Posted some architectural/update path questions on the MR.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Forgot: +1 for the principle! This is a blocker for improving usability. 👍

  • Pipeline finished with Canceled
    over 1 year ago
    Total: 69s
    #130550
  • Pipeline finished with Failed
    over 1 year ago
    Total: 183s
    #130555
  • Pipeline finished with Failed
    about 1 year ago
    Total: 165s
    #213773
  • Pipeline finished with Failed
    about 1 year ago
    Total: 240s
    #213801
  • Pipeline finished with Failed
    about 1 year ago
    Total: 165s
    #213807
  • Pipeline finished with Failed
    about 1 year ago
    Total: 179s
    #213815
  • Pipeline finished with Failed
    about 1 year ago
    Total: 510s
    #213821
  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    Drupal 10.3.x patch

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    Sorry, the last patch was wrong. Here's a 10.3 version

  • Pipeline finished with Failed
    about 1 year ago
    Total: 499s
    #214234
  • 🇵🇱Poland alorenc Wolsztyn, 🇵🇱

    Rolled 2765065-10.3.x-154.diff to Drupal 10.4.x

  • Pipeline finished with Failed
    6 days ago
    Total: 129s
    #597035
  • Pipeline finished with Failed
    6 days ago
    Total: 170s
    #597042
  • Pipeline finished with Failed
    6 days ago
    Total: 573s
    #597055
  • Pipeline finished with Canceled
    5 days ago
    Total: 93s
    #597082
  • Merge request !1321311.2.x version → (Open) created by claudiu.cristea
  • Pipeline finished with Canceled
    5 days ago
    Total: 93s
    #597085
  • Pipeline finished with Failed
    5 days ago
    Total: 342s
    #597084
  • Pipeline finished with Failed
    5 days ago
    #597086
  • Pipeline finished with Failed
    5 days ago
    Total: 739s
    #597095
  • Pipeline finished with Failed
    5 days ago
    #597096
  • Pipeline finished with Failed
    5 days ago
    #597131
  • Pipeline finished with Failed
    5 days ago
    #597130
  • Pipeline finished with Failed
    5 days ago
    #597163
  • Pipeline finished with Running
    5 days ago
    #597171
  • Pipeline finished with Running
    5 days ago
    #597172
  • Pipeline finished with Failed
    5 days ago
    #597182
  • Pipeline finished with Failed
    5 days ago
    #597181
  • Pipeline finished with Running
    5 days ago
    #597244
  • Pipeline finished with Running
    5 days ago
    #597246
  • Pipeline finished with Failed
    5 days ago
    Total: 788s
    #597690
Production build 0.71.5 2024