Commit af1ea7bf authored by alexpott's avatar alexpott

Issue #2066445 by mparker17, rpayanm, aspilicious, tkuldeep17,...

Issue #2066445 by mparker17, rpayanm, aspilicious, tkuldeep17, adci_contributor, Mile23, vijaycs85, alvar0hurtad0, rahulbile, andypost, valthebald: Convert a bunch of AjaxResponse callbacks in system.module's test's ajax_test.module to a new style controller
parent a4df58b1
<?php
/**
* @file
* Helper module for Ajax framework tests.
*/
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\AlertCommand;
use Drupal\Core\Ajax\OpenDialogCommand;
use Drupal\Core\Ajax\OpenModalDialogCommand;
use Drupal\Core\Ajax\CloseDialogCommand;
use Drupal\Core\Url;
/**
* Menu callback: Returns AJAX element with #error property set.
*
* @deprecated \Drupal\ajax_test\Controller\AjaxTestController::renderError()
*/
function ajax_test_error() {
$message = '';
$query = \Drupal::request()->query;
if ($query->has('message')) {
$message = $query->get('message');
}
$response = new AjaxResponse();
$response->addCommand(new AlertCommand($message));
return $response;
}
/**
* Menu callback: Close the ajax dialog.
*
* @deprecated \Drupal\ajax_test\Controller\AjaxTestController::dialogClose()
*/
function ajax_test_dialog_close() {
$response = new AjaxResponse();
$response->addCommand(new CloseDialogCommand('#ajax-test-dialog-wrapper-1'));
return $response;
}
......@@ -8,8 +8,11 @@
namespace Drupal\ajax_test\Controller;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\AlertCommand;
use Drupal\Core\Ajax\CloseDialogCommand;
use Drupal\Core\Ajax\HtmlCommand;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides content for dialog tests.
......@@ -80,14 +83,27 @@ public function order() {
}
/**
* @todo Remove ajax_test_error().
* Returns an AjaxResponse with alert command.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* The JSON response object.
*/
public function renderError() {
return ajax_test_error();
public function renderError(Request $request) {
$message = '';
$query = $request->query;
if ($query->has('message')) {
$message = $query->get('message');
}
$response = new AjaxResponse();
$response->addCommand(new AlertCommand($message));
return $response;
}
/**
* @todo Remove ajax_test_dialog().
* Returns a render array of form elements and links for dialog.
*/
public function dialog() {
// Add two wrapper elements for testing non-modal dialogs. Modal dialogs use
......@@ -180,10 +196,15 @@ public function dialog() {
}
/**
* @todo Remove ajax_test_dialog_close().
* Returns an AjaxResponse with command to close dialog.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* The JSON response object.
*/
public function dialogClose() {
return ajax_test_dialog_close();
$response = new AjaxResponse();
$response->addCommand(new CloseDialogCommand('#ajax-test-dialog-wrapper-1'));
return $response;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment