- Issue created by @pdureau
- Status changed to Needs work
5 months ago 2:16pm 27 August 2024 - Merge request !13Issue #3470447 by pdureau: Field formatters compatibility with Layout Builder → (Merged) created by pdureau
- Assigned to mogtofu33
- 🇫🇷France pdureau Paris
Jean,
There may be something wrong with the custom IconFormatter::validateSettings() method:
public function validateSettings(array $element, FormStateInterface $form_state, &$complete_form): void { $values = $form_state->getValues(); $name = $this->fieldDefinition->getName(); $settings = $values['fields'][$name]['settings_edit_form']['settings'] ?? []; unset($settings['icon_settings']); // @todo do we need configuration validation of plugin form? $form_state->setValueForElement($element, $settings); }
$values['fields'][$name]['settings_edit_form']['settings']
seems to mimic the form structure of manage display, so the formatter settings are not saved in layout builder.If I remove the call to validateSettings:
$elements['icon_settings'] = [ '#type' => 'hidden', '#element_validate' => [ [$this, 'validateSettings'], ], ];
the settings are not saved in neither Manage Display nor Layotu Builder.
I don't know which change to make. Do you have an idea?
Field formatter must be tesetd with Manage Dispaly, Layout Builder, and Views.
- First commit to issue fork.
- 🇫🇷France mogtofu33
Fixed for Icon formatter in Layout builder, but can not make it work for Link with Icon as sample values do not populate the icon.
And for now I didn't find hot to do it.
- Status changed to Fixed
5 months ago 4:48pm 27 August 2024 - 🇫🇷France pdureau Paris
Is it possible to avoid doing such condition which is limited to "Manage display" and "Layout builder":?
// Field UI "MAnage display" page. if (isset($values['fields'][$name]['settings_edit_form']['settings'])) { $settings = $values['fields'][$name]['settings_edit_form']['settings']; } // Layout builder UI. elseif (isset($values['settings']['formatter']['settings'])) { $settings = $values['settings']['formatter']['settings']; }
I am afraid the plugin will not work with Views and any other config entity from Drupal contrib leveraging this plugin type
-
mogtofu33 →
committed 22084ef3 on 1.0.x authored by
pdureau →
Issue #3470447 by pdureau, mogtofu33: Field formatters compatibility...
-
mogtofu33 →
committed 22084ef3 on 1.0.x authored by
pdureau →
- Status changed to Fixed
5 months ago 11:56am 29 August 2024 - Issue was unassigned.