Issue #3027240: Undefined index: #parents FormState.php (11.x)
3 unresolved threads
Merge request reports
Activity
added 10 commits
-
2c405b97...e24ba3f4 - 6 commits from branch
project:11.x
- a4695e06 - Issue #3027240: initial commit with changes from original MR 1300 for 9.x...
- 763ee77a - Issue #3027240: applied another '#parents' check from patch #57 for...
- 8046f8e7 - Issue #3027240: rename test class per MR1300 thread -...
- 9508975f - Issue #3027240: removed the error handler in the test in favor of catching the...
Toggle commit list-
2c405b97...e24ba3f4 - 6 commits from branch
61 62 /** 63 * Tests a form with an #after_build that adds an element with no '#parents'. 64 */ 65 public function testUndefinedParentsInAfterBuild() { 66 $form_state = new FormState(); 67 $form_builder = $this->container->get('form_builder'); 68 $error_message = NULL; 69 try { 70 $form_builder->submitForm($this, $form_state); 71 } 72 catch (\Throwable $e) { 73 $error_message = $e->getMessage(); 74 } 75 76 $this->assertTrue(empty($error_message), "The following error occurred during the form submission: {$error_message}"); - Comment on lines +68 to +76
PHPUnit will report the exception nicely as a error, so something like:
68 $error_message = NULL; 69 try { 70 $form_builder->submitForm($this, $form_state); 71 } 72 catch (\Throwable $e) { 73 $error_message = $e->getMessage(); 74 } 75 76 $this->assertTrue(empty($error_message), "The following error occurred during the form submission: {$error_message}"); 68 $this->assertNull($form_builder->submitForm($this, $form_state), "Form submitted without triggering an exception"); would be simpler.
115 /** 116 * Implements hook_form_FORM_ID_alter(). 117 */ 118 function form_test_form_form_after_build_test_alter(&$form, FormStateInterface $form_state, $form_id) { 119 $form['#after_build'][] = '_form_test_after_build'; 120 } 121 122 /** 123 * After build callback to prove !empty check on #parents is necessary. 124 * 125 * @see https://www.drupal.org/project/drupal/issues/3027240 126 */ 127 function _form_test_after_build($element, FormStateInterface $form_state) { 128 // Add a new element to the form that doesn't have #parents set. 129 $element['after_build_item'] = ['#markup' => 'after_build_item']; 130 return $element; - Comment on lines +128 to +130
1169 1169 * {@inheritdoc} 1170 1170 */ 1171 1171 public function getError(array $element) { 1172 if ($errors = $this->getErrors()) { 1172 if (isset($element['#parents']) && $errors = $this->getErrors()) { 1173 1173 $parents = []; 1174 1174 foreach ($element['#parents'] as $parent) { - Comment on lines +1172 to 1174
Please register or sign in to reply