You are here

public function AjaxTestController::dialog in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php \Drupal\ajax_test\Controller\AjaxTestController::dialog()

Returns a render array of form elements and links for dialog.

1 string reference to 'AjaxTestController::dialog'
ajax_test.routing.yml in core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml
core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml

File

core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php, line 108
Contains \Drupal\ajax_test\Controller\AjaxTestController.

Class

AjaxTestController
Provides content for dialog tests.

Namespace

Drupal\ajax_test\Controller

Code

public function 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' => '<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::formBuilder()
    ->getForm('Drupal\\ajax_test\\Form\\AjaxTestDialogForm');

  // Dialog behavior applied to a #type => 'link'.
  $build['link'] = array(
    '#type' => 'link',
    '#title' => 'Link 1 (modal)',
    '#url' => Url::fromRoute('ajax_test.dialog_contents'),
    '#attributes' => array(
      'class' => array(
        'use-ajax',
      ),
      'data-dialog-type' => 'modal',
    ),
  );

  // Dialog behavior applied to links rendered by links.html.twig.
  $build['links'] = array(
    '#theme' => 'links',
    '#links' => array(
      'link2' => array(
        'title' => 'Link 2 (modal)',
        'url' => Url::fromRoute('ajax_test.dialog_contents'),
        'attributes' => array(
          'class' => array(
            'use-ajax',
          ),
          'data-dialog-type' => 'modal',
          'data-dialog-options' => json_encode(array(
            'width' => 400,
          )),
        ),
      ),
      'link3' => array(
        'title' => 'Link 3 (non-modal)',
        'url' => Url::fromRoute('ajax_test.dialog_contents'),
        'attributes' => array(
          'class' => array(
            'use-ajax',
          ),
          'data-dialog-type' => '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)',
        'url' => Url::fromRoute('ajax_test.dialog_close'),
        'attributes' => array(
          'class' => array(
            'use-ajax',
          ),
          'data-dialog-type' => 'modal',
        ),
      ),
      'link5' => array(
        'title' => 'Link 5 (form)',
        'url' => Url::fromRoute('ajax_test.dialog_form'),
        'attributes' => array(
          'class' => array(
            'use-ajax',
          ),
          'data-dialog-type' => 'modal',
        ),
      ),
      'link6' => array(
        'title' => 'Link 6 (entity form)',
        'url' => Url::fromRoute('contact.form_add'),
        'attributes' => array(
          'class' => array(
            'use-ajax',
          ),
          'data-dialog-type' => 'modal',
          'data-dialog-options' => json_encode(array(
            'width' => 800,
            'height' => 500,
          )),
        ),
      ),
      'link7' => array(
        'title' => 'Link 7 (non-modal, no target)',
        'url' => Url::fromRoute('ajax_test.dialog_contents'),
        'attributes' => array(
          'class' => array(
            'use-ajax',
          ),
          'data-dialog-type' => 'dialog',
          'data-dialog-options' => json_encode(array(
            'width' => 800,
          )),
        ),
      ),
    ),
  );
  return $build;
}