diff --git a/core/modules/outside_in/src/OffCanvasFormDialogTrait.php b/core/modules/outside_in/src/OffCanvasFormDialogTrait.php index e29e8bb6b2..e265a8cb1c 100644 --- a/core/modules/outside_in/src/OffCanvasFormDialogTrait.php +++ b/core/modules/outside_in/src/OffCanvasFormDialogTrait.php @@ -18,7 +18,7 @@ trait OffCanvasFormDialogTrait { /** - * Is the current request for an AJAX modal dialog. + * Determines if the current request is for an AJAX modal dialog. * * @return bool * TRUE is the current request if for an AJAX modal dialog. @@ -26,15 +26,15 @@ protected function isModalDialog() { $wrapper_format = $this->getRequest() ->get(MainContentViewSubscriber::WRAPPER_FORMAT); - return (in_array($wrapper_format, [ + return in_array($wrapper_format, [ 'drupal_ajax', 'drupal_modal', 'drupal_dialog_off_canvas', - ])) ? TRUE : FALSE; + ]); } /** - * Add modal dialog support to a form. + * Adds modal dialog support to a form. * * @param array $form * An associative array containing the structure of the form. @@ -99,18 +99,17 @@ public function submitFormDialog(array &$form, FormStateInterface $form_state) { '#type' => 'status_messages', '#weight' => -1000, ]; - $response->addCommand(new HtmlCommand('#off-canvas-form', $form)); + $command = new HtmlCommand('#off-canvas-form', $form); } else { if ($redirect_url = $this->getRedirectUrl()) { - $response->addCommand(new RedirectCommand($redirect_url->setAbsolute() - ->toString())); + $command = new RedirectCommand($redirect_url->setAbsolute()->toString()); } else { - $response->addCommand(new CloseDialogCommand('#drupal-off-canvas')); + return $this->closeDialog($form, $form_state); } } - return $response; + return $response->addCommand($command); } /** @@ -125,9 +124,7 @@ public function submitFormDialog(array &$form, FormStateInterface $form_state) { * An AJAX response that display validation error messages. */ public function closeDialog(array &$form, FormStateInterface $form_state) { - $response = new AjaxResponse(); - $response->addCommand(new CloseDialogCommand('#drupal-off-canvas')); - return $response; + return (new AjaxResponse())->addCommand(new CloseDialogCommand('#drupal-off-canvas')); } /** @@ -167,8 +164,6 @@ protected function getDestinationUrl() { if ($destination = $this->getRedirectDestinationPath()) { return Url::fromUserInput('/' . $destination); } - - return NULL; } /** @@ -181,7 +176,6 @@ protected function getRedirectDestinationPath() { if ($this->requestStack->getCurrentRequest()->get('destination')) { return $this->getRedirectDestination()->get(); } - return NULL; } /** diff --git a/core/modules/outside_in/src/Render/MainContent/OffCanvasRender.php b/core/modules/outside_in/src/Render/MainContent/OffCanvasRender.php index b03ab22c0e..2c447fab64 100644 --- a/core/modules/outside_in/src/Render/MainContent/OffCanvasRender.php +++ b/core/modules/outside_in/src/Render/MainContent/OffCanvasRender.php @@ -42,13 +42,11 @@ public function renderResponse(array $main_content, Request $request, RouteMatch $response = new AjaxResponse(); // Add place holder form messages from Ajax form requests. - $main_content = [ - 'off_canvas_messages' => [ - '#type' => 'container', - '#attributes' => ['class' => ['messages__wrapper']], - '#weight' => 100, - ], - ] + $main_content; + $main_content['off_canvas_messages'] = [ + '#type' => 'container', + '#attributes' => ['class' => ['messages__wrapper']], + '#weight' => 100, + ]; // First render the main content, because it might provide a title. $content = $this->renderer->renderRoot($main_content); diff --git a/core/modules/outside_in/tests/modules/off_canvas_test/src/Form/TestForm.php b/core/modules/outside_in/tests/modules/off_canvas_test/src/Form/TestForm.php index 0e40595054..e561e9f595 100644 --- a/core/modules/outside_in/tests/modules/off_canvas_test/src/Form/TestForm.php +++ b/core/modules/outside_in/tests/modules/off_canvas_test/src/Form/TestForm.php @@ -55,12 +55,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { } /** - * Form submission handler. - * - * @param array $form - * An associative array containing the structure of the form. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. + * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { drupal_set_message('submitted'); diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php index 12b979dbc5..5c2facb6dd 100644 --- a/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php @@ -121,7 +121,7 @@ protected function getTestThemes() { } /** - * Test form errors in the Off-Canvas dialog. + * Tests form errors in the Off-Canvas dialog. */ public function testFormErrors() { $web_assert = $this->assertSession(); diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php index ea2fe948fb..129aaec7ec 100644 --- a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInJavascriptTestBase.php @@ -141,7 +141,7 @@ protected function getTestThemes() { } /** - * Assert the specified selector is visible after a wait. + * Asserts the specified selector is visible after a wait. * * @param string $selector * The selector engine name. See ElementInterface::findAll() for the