function AjaxTestController::dialog

Same name in other branches
  1. 9 core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php \Drupal\ajax_test\Controller\AjaxTestController::dialog()
  2. 8.9.x core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php \Drupal\ajax_test\Controller\AjaxTestController::dialog()
  3. 10 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 209

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.