1 ajax_test.module ajax_test_dialog()

Menu callback: Renders a form elements and links with #ajax['dialog'].

File

core/modules/simpletest/tests/ajax_test.module, line 78
Helper module for Ajax framework tests.

Code

function ajax_test_dialog() {
  backdrop_add_library('system', 'backdrop.ajax');

  // Add two wrapper elements for testing non-modal dialogs. Modal dialogs use
  // the global backdrop-modal wrapper by default.
  $build['dialog_wrappers'] = array('#markup' => '<div id="ajax-test-dialog-wrapper-1"></div><div id="ajax-test-dialog-wrapper-2"></div>');

  // Dialog behavior applied to a button.
  $build['form'] = backdrop_get_form('ajax_test_dialog_form');

  // Dialog behavior applied to a #type => 'link'.
  $build['client_side_title']['#markup'] = '<h2>Client-side dialog links</h2><p>These links have no special server-side handling. They request a normal page as a dialog. They use the "use-ajax" class combined with the "data-dialog" and "data-dialog-options" properties.</p>';
  $build['client_side_links'] = array(
    '#theme' => 'links',
    '#links' => array(
      'link1' => array(
        'title' => 'Link 1 (modal)',
        'href' => 'ajax-test/dialog-contents/0/1',
        'attributes' => array(
          'class' => array('use-ajax'),
          'data-dialog' => 'true',
        ),
      ),
      'link2' => array(
        'title' => 'Link 2 (non-modal)',
        'href' => 'ajax-test/dialog-contents/0/1',
        'attributes' => array(
          'class' => array('use-ajax'),
          'data-dialog' => 'true',
          'data-dialog-options' => json_encode(array('target' => '#ajax-test-dialog-wrapper-1')),
        ),
      ),
    ),
  );

  $build['server_side_title']['#markup'] = '<h2>Server-side dialog links</h2><p>These links only have the "use-ajax" class and all dialog handling is server-side.</p>';
  $build['server_side_links'] = array(
    '#theme' => 'links',
    '#links' => array(
      'link2' => array(
        'title' => 'Link 1 (modal)',
        'href' => 'ajax-test/dialog-contents/nojs/1',
        'attributes' => array('class' => array('use-ajax')),
      ),
      'link3' => array(
        'title' => 'Link 2 (non-modal)',
        'href' => 'ajax-test/dialog-contents/nojs',
        'attributes' => array('class' => array('use-ajax')),
      ),
      'link4' => array(
        'title' => 'Link 3 (close non-modal if open)',
        'href' => 'ajax-test/dialog-close',
        'attributes' => array('class' => array('use-ajax')),
      ),
    ),
  );
  return $build;
}