Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / modules / views_test_modal / src / Controller / TestController.php
1 <?php
2
3 namespace Drupal\views_test_modal\Controller;
4
5 use Drupal\Component\Serialization\Json;
6 use Drupal\Core\Controller\ControllerBase;
7 use Drupal\Core\Url;
8
9 class TestController extends ControllerBase {
10
11   /**
12    * Renders a link to open the /admin/content view in a modal dialog.
13    */
14   public function modal() {
15     $build = [];
16
17     $build['open_admin_content'] = [
18       '#type' => 'link',
19       '#title' => $this->t('Administer content'),
20       '#url' => Url::fromUserInput('/admin/content'),
21       '#attributes' => [
22         'class' => ['use-ajax'],
23         'data-dialog-type' => 'modal',
24         'data-dialog-options' => Json::encode([
25           'dialogClass' => 'views-test-modal',
26           'height' => '50%',
27           'width' => '50%',
28           'title' => $this->t('Administer content'),
29         ]),
30       ],
31       '#attached' => [
32         'library' => [
33           'core/drupal.dialog.ajax',
34         ],
35       ],
36     ];
37
38     return $build;
39   }
40
41 }