diff --git a/core/modules/system/tests/modules/ajax_test/ajax_test.module b/core/modules/system/tests/modules/ajax_test/ajax_test.module index 2ea9eb9..2f6a7d9 100644 --- a/core/modules/system/tests/modules/ajax_test/ajax_test.module +++ b/core/modules/system/tests/modules/ajax_test/ajax_test.module @@ -21,176 +21,6 @@ function ajax_test_system_theme_info() { } /** - * Menu callback: Returns an element suitable for use by ajax_render(). - * - * Additionally ensures that ajax_render() incorporates JavaScript settings - * generated during the page request by invoking _drupal_add_js() with a dummy - * setting. - * - * @deprecated \Drupal\ajax_test\Controller\AjaxTestController::render() - */ -function ajax_test_render() { - $attached = array( - '#attached' => array( - 'js' => array( - 0 => array( - 'type' => 'setting', - 'data' => array('ajax' => 'test'), - ), - ), - ), - ); - drupal_render($attached); - $response = new AjaxResponse(); - return $response; -} - -/** - * Menu callback: Returns an AjaxResponse; settings command set last. - * - * Helps verifying AjaxResponse reorders commands to ensure correct execution. - * - * @deprecated \Drupal\ajax_test\Controller\AjaxTestController::order() - */ -function ajax_test_order() { - $response = new AjaxResponse(); - $path = drupal_get_path('module', 'system'); - // HTML insertion command. - $response->addCommand(new HtmlCommand('body', 'Hello, world!')); - $attached = array( - '#attached' => array( - 'css' => array( - // Add two CSS files (order should remain the same). - $path . '/css/system.admin.css' => array(), - $path . '/css/system.maintenance.css' => array(), - ), - 'js' => array( - // Add two JavaScript files (first to the footer, should appear last). - $path . '/system.modules.js' => array('scope' => 'footer'), - $path . '/system.js' => array(), - // Finally, add a JavaScript setting. - 0 => array( - 'type' => 'setting', - 'data' => array('ajax' => 'test'), - ), - ), - ), - ); - drupal_render($attached); - return $response; -} - -/** - * 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: Renders a form elements and links with #ajax['dialog']. - * - * @deprecated \Drupal\ajax_test\Controller\AjaxTestController::dialog() - */ -function ajax_test_dialog() { - // Add two wrapper elements for testing non-modal dialogs. Modal dialogs use - // the global drupal-modal wrapper by default. - $build['dialog_wrappers'] = array('#markup' => '
'); - - // Dialog behavior applied to a button. - $build['form'] = drupal_get_form('ajax_test_dialog_form'); - - // Dialog behavior applied to a #type => 'link'. - $build['link'] = array( - '#type' => 'link', - '#title' => 'Link 1 (modal)', - '#href' => 'ajax-test/dialog-contents', - '#attributes' => array( - 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-modal', - ), - ); - - // Dialog behavior applied to links rendered by theme_links(). - $build['links'] = array( - '#theme' => 'links', - '#links' => array( - 'link2' => array( - 'title' => 'Link 2 (modal)', - 'href' => 'ajax-test/dialog-contents', - 'attributes' => array( - 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-modal', - 'data-dialog-options' => json_encode(array( - 'width' => 400, - )) - ), - ), - 'link3' => array( - 'title' => 'Link 3 (non-modal)', - 'href' => 'ajax-test/dialog-contents', - 'attributes' => array( - 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-dialog', - 'data-dialog-options' => json_encode(array( - 'target' => 'ajax-test-dialog-wrapper-1', - 'width' => 800, - )) - ), - ), - 'link4' => array( - 'title' => 'Link 4 (close non-modal if open)', - 'href' => 'ajax-test/dialog-close', - 'attributes' => array( - 'class' => array('use-ajax'), - ), - ), - 'link5' => array( - 'title' => 'Link 5 (form)', - 'href' => 'ajax-test/dialog-form', - 'attributes' => array( - 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-modal', - ), - ), - 'link6' => array( - 'title' => 'Link 6 (entity form)', - 'href' => 'admin/structure/contact/add', - 'attributes' => array( - 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-modal', - 'data-dialog-options' => json_encode(array( - 'width' => 800, - 'height' => 500, - )) - ), - ), - 'link7' => array( - 'title' => 'Link 7 (non-modal, no target)', - 'href' => 'ajax-test/dialog-contents', - 'attributes' => array( - 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-dialog', - 'data-dialog-options' => json_encode(array( - 'width' => 800, - )) - ), - ), - ), - ); - return $build; -} - -/** * Form builder: Renders buttons with #ajax['dialog']. */ function ajax_test_dialog_form($form, &$form_state) { @@ -284,14 +114,3 @@ function ajax_test_dialog_contents() { return $content; } - -/** - * 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; -} diff --git a/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/Controller/AjaxTestController.php b/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/Controller/AjaxTestController.php index b6d5be0..a775983 100644 --- a/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/Controller/AjaxTestController.php +++ b/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/Controller/AjaxTestController.php @@ -7,6 +7,12 @@ namespace Drupal\ajax_test\Controller; +use Drupal\Core\Ajax\AddCssCommand; +use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\HtmlCommand; +use Drupal\Core\Ajax\SettingsCommand; +use Symfony\Component\HttpFoundation\Request; + /** * Provides content for dialog tests. */ @@ -24,35 +30,152 @@ public function dialogContents() { * @todo Remove ajax_test_render(). */ public function render() { - return ajax_test_render(); + $response = new AjaxResponse(); + $response->addCommand(new SettingsCommand(array('ajax' => 'test'))); + return $response; } /** - * @todo Remove ajax_test_order(). + * Helps verifying AjaxResponse reorders commands to ensure correct execution. */ public function order() { - return ajax_test_order(); + $response = new AjaxResponse(); + $path = drupal_get_path('module', 'system'); + $build = array(); + + // HTML insertion command. + $build['content'] = array( + '#type' => 'markup', + '#markup' => 'Hello, world!', + ); + // Add two CSS files (order should remain the same). + $build['#attached']['css'] = array( + $path . '/css/system.admin.css', + $path . '/css/system.maintenance.css', + ); + // Add two JavaScript files (first to the footer, should appear last). + $build['#attached']['js'] = array( + $path . '/system.modules.js', + $path . '/system.js', + ); + $response->addCommand(new HtmlCommand('body', $build)); + // Finally, add a JavaScript setting. + $response->addCommand(new SettingsCommand(array('ajax' => 'test'))); + return $response; } /** - * @todo Remove ajax_test_error(). + * Returns AJAX element with #error property set. */ - public function renderError() { - return ajax_test_error(); + public function renderError(Request $request) { + $message = ''; + if ($request->query->has('message')) { + $message = $request->query->get('message'); + } + $response = new AjaxResponse(); + $response->addCommand(new AlertCommand($message)); + return $response; } /** * @todo Remove ajax_test_dialog(). */ public function dialog() { - return ajax_test_dialog(); + // Add two wrapper elements for testing non-modal dialogs. Modal dialogs use + // the global drupal-modal wrapper by default. + $build['dialog_wrappers'] = array('#markup' => '
'); + + // Dialog behavior applied to a button. + $build['form'] = \Drupal::formBuilder()->getForm('ajax_test_dialog_form'); + + // Dialog behavior applied to a #type => 'link'. + $build['link'] = array( + '#type' => 'link', + '#title' => 'Link 1 (modal)', + '#href' => 'ajax-test/dialog-contents', + '#attributes' => array( + 'class' => array('use-ajax'), + 'data-accepts' => 'application/vnd.drupal-modal', + ), + ); + + // Dialog behavior applied to links rendered by theme_links(). + $build['links'] = array( + '#theme' => 'links', + '#links' => array( + 'link2' => array( + 'title' => 'Link 2 (modal)', + 'href' => 'ajax-test/dialog-contents', + 'attributes' => array( + 'class' => array('use-ajax'), + 'data-accepts' => 'application/vnd.drupal-modal', + 'data-dialog-options' => json_encode(array( + 'width' => 400, + )) + ), + ), + 'link3' => array( + 'title' => 'Link 3 (non-modal)', + 'href' => 'ajax-test/dialog-contents', + 'attributes' => array( + 'class' => array('use-ajax'), + 'data-accepts' => 'application/vnd.drupal-dialog', + 'data-dialog-options' => json_encode(array( + 'target' => 'ajax-test-dialog-wrapper-1', + 'width' => 800, + )) + ), + ), + 'link4' => array( + 'title' => 'Link 4 (close non-modal if open)', + 'href' => 'ajax-test/dialog-close', + 'attributes' => array( + 'class' => array('use-ajax'), + ), + ), + 'link5' => array( + 'title' => 'Link 5 (form)', + 'href' => 'ajax-test/dialog-form', + 'attributes' => array( + 'class' => array('use-ajax'), + 'data-accepts' => 'application/vnd.drupal-modal', + ), + ), + 'link6' => array( + 'title' => 'Link 6 (entity form)', + 'href' => 'admin/structure/contact/add', + 'attributes' => array( + 'class' => array('use-ajax'), + 'data-accepts' => 'application/vnd.drupal-modal', + 'data-dialog-options' => json_encode(array( + 'width' => 800, + 'height' => 500, + )) + ), + ), + 'link7' => array( + 'title' => 'Link 7 (non-modal, no target)', + 'href' => 'ajax-test/dialog-contents', + 'attributes' => array( + 'class' => array('use-ajax'), + 'data-accepts' => 'application/vnd.drupal-dialog', + 'data-dialog-options' => json_encode(array( + 'width' => 800, + )) + ), + ), + ), + ); + return $build; } /** - * @todo Remove ajax_test_dialog_close(). + * Close the ajax dialog. */ public function dialogClose() { - return ajax_test_dialog_close(); + $response = new AjaxResponse(); + $response->addCommand(new CloseDialogCommand('#ajax-test-dialog-wrapper-1')); + return $response; } }