Skip to content
Snippets Groups Projects

Issue #3481540 by just_like_good_vibes: FieldFormatterSource: some settings are not saved

Files
4
@@ -72,9 +72,46 @@ class ComponentForm extends ComponentFormBase {
[$class, 'validateFormElement'],
],
'#theme_wrappers' => ['form_element'],
'#after_build' => [
[$class, 'afterBuild'],
],
];
}
/**
* Alter the element after the form is built.
*
* @param array $element
* The element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*
* @return array
* The altered element.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public static function afterBuild(array $element, FormStateInterface $form_state) : array {
if ($form_state->isProcessingInput()) {
// For browser-submitted forms, the submitted values do not contain
// values for certain elements (empty multiple select, unchecked
// checkbox). Child elements are processed after the parent element,
// The processed values, stored in '#value', are bubbled up to the
// parent element here and then copied to the form state.
if (isset($element['#value'])) {
if (isset($element['slots']) && isset($element['slots']['#value'])) {
$element['#value']['slots'] = $element['slots']['#value'];
}
if (isset($element['props']) && isset($element['props']['#value'])) {
$element['#value']['props'] = $element['props']['#value'];
}
}
}
// Recopy the value to the form state.
$form_state->setValueForElement($element, $element['#value']);
return $element;
}
/**
* {@inheritdoc}
*/
@@ -309,7 +346,6 @@ class ComponentForm extends ComponentFormBase {
return;
}
if (isset($element["#component_validation"]) && !$element["#component_validation"]) {
$form_state->setValueForElement($element, $element['#value']);
return;
}
try {
@@ -326,7 +362,6 @@ class ComponentForm extends ComponentFormBase {
$renderer->executeInRenderContext($context, function () use (&$build, $renderer) {
return $renderer->render($build);
});
$form_state->setValueForElement($element, $element['#value']);
}
}
catch (\Throwable $e) {
Loading