By dawehner on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Introduced in version:
8.0.0-beta11
Issue links:
Description:
Modals are now using query parameters instead of accept headers, so for example test code to request a specific
page as modal would have the change like the following:
Before
$ajax_result = $this->drupalGetAjax('ajax-test/dialog-contents', array(), array('Accept: application/vnd.drupal-modal'));
After
$ajax_result = $this->drupalGetAjax('ajax-test/dialog-contents', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal')));
In case you generate some ajax settings its looking a bit different:
Before
'#ajax' => [
'callback' => '::preview',
'event' => 'click',
'url' => Url::fromRoute('system.ajax')->toString(),
'dialogType' => 'modal',
'accepts' => 'application/vnd.drupal-ajax',
]
After
'#ajax' => [
'callback' => '::preview',
'event' => 'click',
'url' => Url::fromRoute('system.ajax')->toString(),
'dialogType' => 'modal',
]
If adding a modal in a render array, the change is similar to the above example, just not camelCased:
Before
'attributes' => [
'class' => ['use-ajax'],
'data-accepts' => 'application/vnd.drupal-modal',
'data-dialog-options' => Json::encode([
'width' => 700,
]),
],
After
'attributes' => [
'class' => ['use-ajax'],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 700,
]),
],
A complete example of a link opening in a dialog:
return [
'#type' => 'link',
'#title' => $this->t('Some text'),
'#url' => Url::fromRoute('some.route', [], ['query' => $this->getDestinationArray()]),
'#options' => ['attributes' => [
'class' => ['use-ajax'],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 700,
]),
]],
'#attached' => ['library' => ['core/drupal.dialog.ajax']],
];
Most importantly, don't forget to attach the dialog library.
Impacts:
Module developers