function NestedEntityTestForm::validateForm
Same name in other branches
- 9 core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php \Drupal\field_test\Form\NestedEntityTestForm::validateForm()
- 8.9.x core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php \Drupal\field_test\Form\NestedEntityTestForm::validateForm()
- 10 core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php \Drupal\field_test\Form\NestedEntityTestForm::validateForm()
Overrides FormBase::validateForm
File
-
core/
modules/ field/ tests/ modules/ field_test/ src/ Form/ NestedEntityTestForm.php, line 73
Class
- NestedEntityTestForm
- Provides a form for field_test routes.
Namespace
Drupal\field_test\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$entity_1 = $form_state->get('entity_1');
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display_1 */
$form_display_1 = $form_state->get('form_display_1');
$form_display_1->extractFormValues($entity_1, $form, $form_state);
$form_display_1->validateFormValues($entity_1, $form, $form_state);
$entity_2 = $form_state->get('entity_2');
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display_2 */
$form_display_2 = $form_state->get('form_display_2');
$extracted = $form_display_2->extractFormValues($entity_2, $form['entity_2'], $form_state);
// Extract the values of fields that are not rendered through widgets, by
// simply copying from top-level form values. This leaves the fields that
// are not being edited within this form untouched.
// @see \Drupal\Tests\field\Functional\NestedFormTest::testNestedEntityFormEntityLevelValidation()
foreach ($form_state->getValues()['entity_2'] as $name => $values) {
if ($entity_2->hasField($name) && !isset($extracted[$name])) {
$entity_2->set($name, $values);
}
}
$form_display_2->validateFormValues($entity_2, $form['entity_2'], $form_state);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.