Allow FieldGroupFormatter to massage values

Created on 15 May 2025, 22 days ago

Problem/Motivation

I try to add to the settings form of a field group a complex element, but i cannot change values.

I create a field group details icon which is base on details field group, but on which i can add and configure an icon to display with label.
I use icon_autocomplete widget, which return values composed by an IconDefinition object and settings as array.
I don't want to store all the IconDefinition in my schema, but only pack_id and icon_id.

Unfortunately, i cannot edit this values before they are casted and validated to be stored.

Steps to reproduce

Add in the settings form of a new field group :


    $icon = NULL;
    if ($this->getSetting('icon') && isset($this->getSetting('icon')['icon'])) {
      $icon = $this->getSetting('icon')['icon'];
    }
    $form['icon'] = [
      '#title' => $this->t('Icon'),
      '#type' => 'icon_autocomplete',
      '#default_value' => $icon ? "{$icon['pack_id']}:{$icon['icon_id']}" : NULL,
      '#default_settings' => $this->getSetting('icon') ? $this->getSetting('icon')['settings'] : NULL,
    ];

Proposed resolution

Like Form widget do, add a massageFormValues() methods so plugin can alter values to make them storable.

In FieldGroupAddForm


      $new_group->format_settings = $form_state->getValue('format_settings');

      $manager = $this->fieldGroupFormatterPluginManager;
      $plugin = $manager->getInstance([
        'format_type' => $new_group->format_type,
        'configuration' => [
          'label' => $new_group->label,
          'settings' => $new_group->format_settings,
        ],
        'group' => $new_group,
      ]);

      $plugin->massageFormValues($new_group->format_settings);

Remaining tasks

Submit MR

Feature request
Status

Active

Version

3.0

Component

Code

Created by

🇫🇷France goz

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024