Use entity label in user messaging

Created on 3 November 2023, 8 months ago

Problem/Motivation

We are using licenses for a site that has paid memberships. The language on the site uses "membership" instead of "license". We overrode the entity definition label so all the built-in messaging and UX would be consistent. However, the word "License" is hard-coded into some user facing elements.

Yes, we could use translation to overcome this issue, but that's much more complicated than just using the entity type label by default.

Steps to reproduce

Add a hook like this to a custom module:


/**
 * Implements hook_entity_type_alter().
 */
function mymodule_entity_type_alter(array &$entity_types) {
  $entity_types['commerce_license']->set('label', t('Membership'));
}

Buy a membership with a user. Then add another membership to your cart so you get a system message about already having a License. It will show "License" not "membership"

Proposed resolution

Where "license" is hardcoded into messages, just grab the entity type label instead.

Remaining tasks

I only caught a couple of messages that appear in our implementation, so there are a few more instances of messages that need this change applied.

User interface changes

UX feedback becomes more dynamic based on the entity type definition.

API changes

none.

Data model changes

none.

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States gcb

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

Comments & Activities

Production build 0.69.0 2024