function TestController::modal

Same name in other branches
  1. 9 core/modules/views/tests/modules/views_test_modal/src/Controller/TestController.php \Drupal\views_test_modal\Controller\TestController::modal()
  2. 8.9.x core/modules/views/tests/modules/views_test_modal/src/Controller/TestController.php \Drupal\views_test_modal\Controller\TestController::modal()
  3. 11.x core/modules/views/tests/modules/views_test_modal/src/Controller/TestController.php \Drupal\views_test_modal\Controller\TestController::modal()

Renders a link to open the /admin/content view in a modal dialog.

1 string reference to 'TestController::modal'
views_test_modal.routing.yml in core/modules/views/tests/modules/views_test_modal/views_test_modal.routing.yml
core/modules/views/tests/modules/views_test_modal/views_test_modal.routing.yml

File

core/modules/views/tests/modules/views_test_modal/src/Controller/TestController.php, line 14

Class

TestController

Namespace

Drupal\views_test_modal\Controller

Code

public function modal() {
    $build = [];
    $build['open_admin_content'] = [
        '#type' => 'link',
        '#title' => $this->t('Administer content'),
        '#url' => Url::fromUserInput('/admin/content'),
        '#attributes' => [
            'class' => [
                'use-ajax',
            ],
            'data-dialog-type' => 'modal',
            'data-dialog-options' => Json::encode([
                'classes' => [
                    'ui-dialog' => 'views-test-modal',
                ],
                'height' => '50%',
                'width' => '50%',
                'title' => $this->t('Administer content'),
            ]),
        ],
        '#attached' => [
            'library' => [
                'core/drupal.dialog.ajax',
            ],
        ],
    ];
    return $build;
}

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