Problem/Motivation
Currently when creating link to open in modal the developer must do something like:
'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',
],
],
In both cases the developer must add the class 'use-ajax' but all dialogs like this will use the ajax system.
This is confusing because it gives the impression that you could make a dialog like and have it not use ajax if you left off this class but in fact if you leave off this class the link will not be a dialog link at all.
Proposed resolution
Automatically add the 'use-ajax' class if data-dialog-type is provided.
Remaining tasks
Review
User interface changes
None
API changes
To make a dialog link you won't have to add 'use-ajax' class manually.
Data model changes
None
Comments
Comment #2
tedbowHere is the patch.
Not sure where else we should add test coverage
Comment #4
tedbowTested passed after DrupalCI error
Comment #5
berdirWhy not deal with this directly in \Drupal\Core\Render\Element\Link::preRenderLink()? We already have ajax stuff there.
Comment #7
borisson_I think that #5 makes sense, let's move it there, we can keep the testcoverage added in #2.
Comment #12
matroskeenI was using dialog windows recently, so I think it can be a nice improvement of developer experience.
Here is a re-roll that contains 2 minor changes:
1) Moved code from system_link_alter() to Drupal\Core\Render\Element\Link::preRenderLink();
2) Replaced assertNotContains() with assertStringNotContainsString();
Comment #14
tanubansal commentedChanges mentioned in #12 are successfully applied on 9.1
Comment #15
tedbow@Matroskeen thanks for the fixes. I think this changes are good. I would RTBC but since I create the original patch I don't think I should.
but looking at the patch I think there are a couple comments and string changes we could add to make it more clear what we are testing.
Hopefully this is clearer
Looking a back at this the array key and the link title are confusing. "Normal Module Class Added" to me now reads as there is class "normal-modal" and it was added. Changing both of this to be more clear.
We don't have a comment here as to what we are actually testing and the link title is confusing. Adding a comment.
Comment #18
ranjith_kumar_k_u commented.
Comment #19
ranjith_kumar_k_u commentedRe-rolled #15 for 9.4
Comment #20
ranjith_kumar_k_u commentedComment #24
smethawee commentedIs 9.4.8 working? and how to fix this issue. Could anybody help please.
Thanks!