Allow easily creating dialog links

Created on 13 February 2018, over 7 years ago
Updated 23 April 2025, about 1 month ago

Problem/Motivation

To make a dialog link in Drupal you have know to do this

'normal_modal' => [
        '#title' => 'Normal Modal!',
        '#type' => 'link',
        '#url' => Url::fromRoute('dialog_renderer_test.modal_content'),
        '#attributes' => [
          'class' => ['use-ajax'],
          'data-dialog-type' => 'modal',
        ],
        '#attached' => [
          'library' => [
            'core/drupal.ajax',
          ],
        ],
      ],

To use the off-canvas dialog:

'off_canvas_link_1' => [
        '#title' => 'Click Me 1!',
        '#type' => 'link',
        '#url' => Url::fromRoute('off_canvas_test.thing1'),
        '#attributes' => [
          'class' => ['use-ajax'],
          'data-dialog-type' => 'dialog',
          'data-dialog-renderer' => 'off_canvas',
        ],
      ],

You have to know about data-dialog-type, use-ajax, data-dialog-renderer.

But now we have Link objects and \Drupal\Core\Link::toRenderable
So making regular links is easier but we can't make dialog links this way.

Proposed resolution

Make it really easy and obvious to make dialog links.

Add \Drupal\Core\Link::openInDailog()

Remaining tasks

  1. Update ::toString() to handle new attributes.
  2. Create tests
  3. Create change record

User interface changes

None

API changes

New method

Data model changes

None

โœจ Feature request
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component

render system

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024