[2.0.7] Fix callback name fallback

Created on 8 August 2025, 6 days ago

Problem/Motivation

Related to 🐛 TypeError: ltrim(): Argument #1 ($string) must be of type string, Active so @juc1 will be credited.

We have an issue with this ComponentPluginManager method:

   protected function processDefinitionCategory(&$definition): void {
     // Name is mandatory, so undefined should never happen.
     $definition['label'] = $definition['name'] ?? $this->t('Undefined');
     $definition['category'] = $definition['group'] ?? $this->t('Other');
   }

The machine name would be better than 'Undefined'
'Undefined' is not a string but a TranslatableMarkup so it breaks type checking
label is replaced but not name so it doesn't work properly when

Proposed resolution

  • use the machine name as a fallback instead of "Undefined"
  • cast TranslatableMarkup as a string
  • Remove label? Where is it used?
🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France pdureau Paris

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

Comments & Activities

  • Issue created by @pdureau
  • 🇬🇧United Kingdom juc1

    pdureau credited juc1 .

  • @pdureau opened merge request.
  • 🇫🇷France pdureau Paris

    Hi Grimreaper,

    this issue is related to 🐛 Library: other group placed first Active which has introduced label & category properties.

    I changed the logic to fix the TypeError but it may not be enough.

    Are we comfortable with the addition of label & category properties to all definitions? We are adding them to a kind of public interface.

    For category, we may have no choice.

    But for label, why not use the $label_key = 'name' property instead?

      public function getSortedDefinitions(?array $definitions = NULL, $label_key = 'label');
      public function getSortedDefinitions(?array $definitions = NULL, $label_key = 'label');
    
  • 🇫🇷France Grimreaper France 🇫🇷

    why not use the $label_key = 'name' property instead?

    It was to minimize changes of 🐛 Library: other group placed first Active because default value for $label_key of CategorizingPluginManagerTrait is "label". So to avoid to edit all calls to getSortedDefinitions or getGroupedDefinitions, especially in case of usage in other contrib ui_patterns modules, or custom code.

    So to avoid a breaking change.

  • 🇫🇷France Grimreaper France 🇫🇷

    I changed the moment default name is set.

    Ok on my side, please retest on your side.

  • 🇫🇷France pdureau Paris

    automerge set

Production build 0.71.5 2024