- Issue created by @michaellenahan
- π©πͺGermany michaellenahan
Digging further, it appears that the problem is unrelated to ECA.
If we disable the ECA, and try to set `['#required'] = TRUE` in code, we get the same results:
- validation error is thrown for cardinality 1 or unlimited
- validation error is not thrown for cardinality > 1 (that is, 2, 3, or some other number)Tested with the following code:
function mymodule_form_alter(&$form, $form_state, $form_id): void { if ($form_id == 'node_page_form') { $form_object = $form_state->getFormObject(); $entity = $form_object->getEntity(); foreach ($entity->getFieldDefinitions() as $field_name => $field_definition) { if ($field_definition->getName() == 'field_file') { // Set the field as required $form[$field_name]['widget'][0]['#required'] = TRUE; } } } }
- Merge request !11883Issue #3519279: Programmatically setting form field as required does not work... β (Open) created by michaellenahan
- π©πͺGermany michaellenahan
Thank you to @tstoeckler and @rodrigoaguilera for your help at Drupal Dev Days Leuven.
Tests are now green, though perhaps more tests are needed. - πΊπΈUnited States smustgrave
Since the fix appears to be in the file module can test be moved there too
Thanks
- π³πΏNew Zealand quietone
Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies β .