diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 64300e7..04b90e5 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -675,10 +675,8 @@ public function prepareForm($form_id, &$form, &$form_state) { $form += $this->getElementInfo('form'); $form += array('#tree' => FALSE, '#parents' => array()); - if (isset($form_state['build_info']['callback_object'])) { - $form['#validate'][] = array($form_state['build_info']['callback_object'], 'validateForm'); - $form['#submit'][] = array($form_state['build_info']['callback_object'], 'submitForm'); - } + $form['#validate'][] = array($form_state['build_info']['callback_object'], 'validateForm'); + $form['#submit'][] = array($form_state['build_info']['callback_object'], 'submitForm'); // If no #theme has been set, automatically apply theme suggestions. // theme_form() itself is in #theme_wrappers and not #theme. Therefore, the diff --git a/core/modules/field/src/Tests/FieldAttachOtherTest.php b/core/modules/field/src/Tests/FieldAttachOtherTest.php index a058dd6..379d108 100644 --- a/core/modules/field/src/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/src/Tests/FieldAttachOtherTest.php @@ -342,6 +342,7 @@ function testEntityFormDisplayExtractFormValues() { $values_2[1]['value'] = 0; // Pretend the form has been built. + $form_state['build_info']['callback_object'] = \Drupal::entityManager()->getFormObject($entity_type, 'default'); \Drupal::formBuilder()->prepareForm('field_test_entity_form', $form, $form_state); drupal_process_form('field_test_entity_form', $form, $form_state); $form_state['values'][$this->field_name] = $values; diff --git a/core/modules/system/src/Tests/Form/ElementsTableSelectTest.php b/core/modules/system/src/Tests/Form/ElementsTableSelectTest.php index 30380ac..b0ce2f8 100644 --- a/core/modules/system/src/Tests/Form/ElementsTableSelectTest.php +++ b/core/modules/system/src/Tests/Form/ElementsTableSelectTest.php @@ -216,6 +216,7 @@ private function formSubmitHelper($form, $edit) { $form_state['input'] = $edit; $form_state['input']['form_id'] = $form_id; + $form_state['build_info']['callback_object'] = new StubForm($form_id, $form); \Drupal::formBuilder()->prepareForm($form_id, $form, $form_state); diff --git a/core/modules/system/src/Tests/Form/FormTest.php b/core/modules/system/src/Tests/Form/FormTest.php index f113bcf..2b4850e 100644 --- a/core/modules/system/src/Tests/Form/FormTest.php +++ b/core/modules/system/src/Tests/Form/FormTest.php @@ -109,6 +109,7 @@ function testRequiredFields() { $form[$element]['#required'] = $required; $form_state['input'][$element] = $empty; $form_state['input']['form_id'] = $form_id; + $form_state['build_info']['callback_object'] = new StubForm($form_id, $form); $form_state['method'] = 'post'; // The form token CSRF protection should not interfere with this test, // so we bypass it by setting the token to FALSE. diff --git a/core/modules/system/src/Tests/Form/StubForm.php b/core/modules/system/src/Tests/Form/StubForm.php new file mode 100644 index 0000000..225371b --- /dev/null +++ b/core/modules/system/src/Tests/Form/StubForm.php @@ -0,0 +1,64 @@ +formId = $form_id; + $this->form = $form; + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + $this->formId; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + return $this->form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + } + +}