diff --git a/core/lib/Drupal/Core/Form/ConfirmFormBase.php b/core/lib/Drupal/Core/Form/ConfirmFormBase.php index 03c7acd..1086d33 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormBase.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormBase.php @@ -47,7 +47,8 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['#title'] = $this->getQuestion(); $form['#attributes']['class'][] = 'confirmation'; - $form['description'] = array('#markup' => $this->getDescription()); + $description = $this->getDescription(); + $form['description'] = is_array($description) ? $description : array('#markup' => $description); $form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1); $form['actions'] = array('#type' => 'actions'); diff --git a/core/lib/Drupal/Core/Form/ConfirmFormInterface.php b/core/lib/Drupal/Core/Form/ConfirmFormInterface.php index 0b67fd3..fe53785 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormInterface.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormInterface.php @@ -31,7 +31,9 @@ public function getCancelUrl(); /** * Returns additional text to display as a description. * - * @return string + * The text can be provided as a translated string or as a renderable array. + * + * @return string|array * The form description. */ public function getDescription(); diff --git a/core/modules/system/src/Tests/Form/ConfirmFormTest.php b/core/modules/system/src/Tests/Form/ConfirmFormTest.php index 92a5aa9..1dbcbcb 100644 --- a/core/modules/system/src/Tests/Form/ConfirmFormTest.php +++ b/core/modules/system/src/Tests/Form/ConfirmFormTest.php @@ -50,6 +50,10 @@ function testConfirmForm() { $this->drupalGet('form-test/confirm-form-array-path'); $this->clickLink(t('ConfirmFormArrayPathTestForm::getCancelText().')); $this->assertUrl('form-test/confirm-form', array('query' => array('destination' => 'admin/config')), "The form's complex cancel link was followed."); + + // Test a confirm form, using a renderable array as description. + $this->drupalGet('form-test/confirm-form-extended'); + $this->assertText(t('ConfirmFormTestForm::getDescription().')); } /** diff --git a/core/modules/system/tests/modules/form_test/form_test.routing.yml b/core/modules/system/tests/modules/form_test/form_test.routing.yml index d8c5833..b23c1a8 100644 --- a/core/modules/system/tests/modules/form_test/form_test.routing.yml +++ b/core/modules/system/tests/modules/form_test/form_test.routing.yml @@ -40,6 +40,13 @@ form_test.route6: requirements: _access: 'TRUE' +form_test.route6_extended: + path: '/form-test/confirm-form-extended' + defaults: + _form: '\Drupal\form_test\ConfirmFormTestExtendedForm' + requirements: + _access: 'TRUE' + form_test.route7: path: '/form-test/confirm-form-array-path' defaults: diff --git a/core/modules/system/tests/modules/form_test/src/ConfirmFormTestExtendedForm.php b/core/modules/system/tests/modules/form_test/src/ConfirmFormTestExtendedForm.php new file mode 100644 index 0000000..13f5f05 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/src/ConfirmFormTestExtendedForm.php @@ -0,0 +1,24 @@ + $this->t('ConfirmFormTestForm::getDescription().'), + ]; + } + +}