Skip to content
Snippets Groups Projects
Commit 0121cce7 authored by Mikael Meulle's avatar Mikael Meulle
Browse files

Merge branch '3516369-regression-on-saving' into '2.0.x'

Resolve #3516369 "Regression on saving"

See merge request !362
parents 679242a8 946c5bf4
No related branches found
No related tags found
No related merge requests found
Pipeline #461563 failed
......@@ -41,6 +41,9 @@ class UiPComponentFormDisplayForm extends FormElementBase {
'#after_build' => [
[$class, 'afterBuild'],
],
'#element_validate' => [
[$class, 'elementValidate'],
],
'#theme_wrappers' => ['form_element'],
];
}
......@@ -88,13 +91,26 @@ class UiPComponentFormDisplayForm extends FormElementBase {
*/
public static function afterBuild(array $element, FormStateInterface $form_state) : array {
if ($form_state->isProcessingInput()) {
if (isset($element['#value'])) {
$form_state->setValueForElement($element, $element['#value']);
}
static::elementValidate($element, $form_state);
}
return $element;
}
/**
* Alter the element during validation.
*
* @param array $element
* The element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
public static function elementValidate(array &$element, FormStateInterface $form_state) : void {
$element['#value'] = $form_state->getValue($element['#parents']);
if (isset($element['#value'])) {
$form_state->setValueForElement($element, $element['#value']);
}
}
/**
* {@inheritdoc}
*/
......
......@@ -113,6 +113,7 @@ class UiPComponentFormDisplaysForm extends ComponentForm {
'#allow_override' => TRUE,
'#component_id' => $component_id,
'#component_required' => $element['#component_required'] ?? FALSE,
'#component_validation' => FALSE,
'#tag_filter' => $element['#tag_filter'] ?? [],
'#ajax_url' => $element['#ajax_url'] ?? NULL,
'#source_contexts' => $element['#source_contexts'] ?? [],
......@@ -146,7 +147,7 @@ class UiPComponentFormDisplaysForm extends ComponentForm {
$element["variant_id"]['#access'] = FALSE;
$element["props"]['#access'] = FALSE;
$element["slots"]['#access'] = FALSE;
$element['#component_validation'] = FALSE;
$element['#component_validation'] = TRUE;
$element["#after_build"] = [
[static::class, 'afterBuild'],
......@@ -173,21 +174,24 @@ class UiPComponentFormDisplaysForm extends ComponentForm {
* {@inheritdoc}
*/
public static function afterBuild(array $element, FormStateInterface $form_state) : array {
if ($form_state->isProcessingInput()) {
return $element;
}
if (isset($element['display']['value']['#value'])) {
$element['#value'] = $element['display']['value']['#value'];
/**
* {@inheritdoc}
*/
public static function elementValidate(array &$element, FormStateInterface $form_state): void {
if (isset($element['display']['value']['#value'])) {
$element['#value'] = $element['display']['value']['#value'];
if (isset($element['display']['display_id'])
if (isset($element['display']['display_id'])
&& $element['display']['display_id']['#value'] !== '_component_form') {
$element['#value']['display_id'] = $element['display']['display_id']['#value'];
}
$element['#value']['component_id'] = $element['display']['component_id']['#value'];
$form_state->setValueForElement($element, $element['#value']);
$element['#value']['display_id'] = $element['display']['display_id']['#value'];
}
$element['#value']['component_id'] = $element['display']['component_id']['#value'];
$form_state->setValueForElement($element, $element['#value']);
}
return $element;
}
}
......@@ -74,13 +74,14 @@ class ComponentForm extends ComponentFormBase {
'#process' => [
[$class, 'buildForm'],
],
'#element_validate' => [
[$class, 'validateFormElement'],
],
'#theme_wrappers' => ['form_element'],
'#after_build' => [
[$class, 'afterBuild'],
],
'#element_validate' => [
[$class, 'elementValidate'],
[$class, 'validateFormElement'],
],
];
}
......@@ -94,30 +95,34 @@ class ComponentForm extends ComponentFormBase {
*
* @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'];
}
}
static::elementValidate($element, $form_state);
}
// Recopy the value to the form state.
$form_state->setValueForElement($element, $element['#value']);
return $element;
}
/**
* {@inheritdoc}
*/
public static function elementValidate(array &$element, FormStateInterface $form_state): void {
// 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'];
}
$form_state->setValueForElement($element, $element['#value']);
}
}
/**
* {@inheritdoc}
*/
......
......@@ -254,24 +254,38 @@ abstract class ComponentFormBase extends FormElementBase implements TrustedCallb
*
* @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 the form_state, are propagated
// to the '#value' of the element here (parents will process).
$element['#value'] = $form_state->getValue($element['#parents']);
// Values are cleaned
// similarly to $form_state->cleanValues();
static::cleanValues($element['#value']);
static::elementValidate($element, $form_state);
}
return $element;
}
/**
* Alter the element during validation.
*
* @param array $element
* The element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
public static function elementValidate(array &$element, FormStateInterface $form_state) : void {
// 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 the form_state, are propagated
// to the '#value' of the element here (parents will process).
$value = $form_state->getValue($element['#parents']);
if ($value === NULL) {
$aa = 1;
}
$element['#value'] = $value;
// Values are cleaned
// similarly to $form_state->cleanValues();
static::cleanValues($element['#value']);
}
/**
* Clean values.
*
......
......@@ -65,6 +65,9 @@ class ComponentPropForm extends ComponentFormBase {
'#after_build' => [
[$class, 'afterBuild'],
],
'#element_validate' => [
[$class, 'elementValidate'],
],
];
}
......
......@@ -65,6 +65,9 @@ class ComponentPropsForm extends ComponentFormBase {
'#after_build' => [
[$class, 'afterBuild'],
],
'#element_validate' => [
[$class, 'elementValidate'],
],
];
}
......
......@@ -85,6 +85,9 @@ class ComponentSlotForm extends ComponentFormBase {
'#after_build' => [
[$class, 'afterBuild'],
],
'#element_validate' => [
[$class, 'elementValidate'],
],
];
}
......
......@@ -58,6 +58,9 @@ class ComponentSlotsForm extends ComponentFormBase {
'#after_build' => [
[$class, 'afterBuild'],
],
'#element_validate' => [
[$class, 'elementValidate'],
],
];
}
......@@ -71,11 +74,24 @@ class ComponentSlotsForm extends ComponentFormBase {
*
* @return array
* The altered element.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public static function afterBuild(array $element, FormStateInterface $form_state) : array {
if ($form_state->isProcessingInput() && isset($element['#value']) && is_array($element['#value'])) {
if ($form_state->isProcessingInput()) {
static::elementValidate($element, $form_state);
}
return $element;
}
/**
* Alter the element after the form is built.
*
* @param array $element
* The element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
public static function elementValidate(array &$element, FormStateInterface $form_state) : void {
if (isset($element['#value']) && is_array($element['#value'])) {
// 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,
......@@ -87,7 +103,6 @@ class ComponentSlotsForm extends ComponentFormBase {
}
}
}
return $element;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment