Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Component form validation should check that a variant isn't being changed without having been updated.
Steps to reproduce
1. Set a variant, press the button to set it, and submit
2. Change the variant value, but don't press the button to update it
3. Submit the form
If the variant has required values, these were not added to the form, but will show a validation error anyway, which is confusing to the user.
Proposed resolution
Something like this ought to work, except the data item already has the form values, so the comparison check always works:
$mutable_validation = [];
$data->walk(function(DataItem $data_item) use ($data_values, &$mutable_validation) {
if (!$data_item->isMutable()) {
return;
}
$variant_data = $data_item->getVariantData();
if ($variant_data->isEmpty()) {
return;
}
$address_pieces = explode(':', $variant_data->getAddress());
array_shift($address_pieces);
$variant_data_form_value = NestedArray::getValue($data_values, $address_pieces);
if ($variant_data_form_value != $variant_data->value) {
$mutable_validation[] = $address_pieces;
}
$mutable_validation[] = $address_pieces;
});
Comments