You are here

function dialog_test_dialog in Dialog 7.2

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

1 string reference to 'dialog_test_dialog'
dialog_test_menu in tests/dialog_test.module
Implements hook_menu().

File

tests/dialog_test.module, line 38
A dummy module for testing dialog related hooks.

Code

function dialog_test_dialog() {
  drupal_add_library('dialog', 'drupal.dialog.ajax');

  // Add two wrapper elements for testing non-modal dialogs. Modal dialogs use
  // the global drupal-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'] = drupal_get_form('dialog_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;
}