Not sure where this belongs exactly.
I updated to 2.x-dev and tested my profile, which has a date field. And it stopped working and I got a validation error about an invalid date format when it was clearly valid.
Some fun debugging later, I tracked this down to the fact that ProfileSelect is a form element which means it has #input TRUE (not actually explicitly set, but all form elements get that automatically). That means it owns everything within it and the value is set in the form_state values.
When nested elements are then processed in \Drupal\Core\Form\FormBuilder::handleInputElement(), it sees that there already are values and doesn't update it:
// Set the element's value in $form_state->getValues(), but only, if its key
// does not exist yet (a #value_callback may have already populated it).
if (!NestedArray::keyExists($form_state->getValues(), $element['#parents'])) {
$form_state->setValueForElement($element, $element['#value']);
}
And then the values for the date field are incomplete and everything falls apart :)
Not exactly sure what needs to happen. I see that form elements like Table are also form elements and it works fine for them obviously. They do have a value callback, so maybe what's needed is a custom value callback that only returns its own value?
Comments
Comment #2
berdirTurns out Table is actually equally broken:
To reproduce, just throw this in NodeForm or any other form:
I'll open a core issue as well for this.
Comment #3
berdir#2857083: Form elements that contain other elements break value callbacks of form elements within them
Comment #4
berdirForgot about this again but then the customer found this as well, created a PR now that converts the base class to a trait, that *seems* to be working, lets see what the tests have to say: https://github.com/drupalcommerce/commerce/pull/721
We could also keep the old class as BC, but I guess you don't care about that yet.
Comment #5
berdirComment #6
mglamanI think we'll be fine. I have a feeling most people are extending classes which already extend that class.
Comment #7
bojanz commentedMerged the PR in 0e6f8627cf44d94f132f1d8c4d6e7e24654eb324, thanks!
Comment #8
replicaobscuraAdding related issue about PaymentGatewayForm
Comment #9
replicaobscura