Currently the experimental widget's modal add form uses jQuery's dialog directly rather than Drupal's wrapper. I've had an issue where I'm trying to style the dialog using Javascript in order to replace the use of background-url CSS some themes use to display the close button as an icon with a FontAwesome close icon we are using throughout our theme.
By using the Drupal.dialog object instead of the jQuery UI dialog, I'm able to attach to the more specific events that Drupal fires, specifically dialog:aftercreate and place the icon much more easily, as it passes the modal body element along with the event.
I realize that jQuery also has events that fire and I could also find the dialog elements on that event, but I think it is a good idea to use the Drupal.dialog object that is available, as I see no downside, and it provides consistency with how dialogs are displayed in Drupal via Javascript.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | paragraphs-use-drupal-dialog-3028468-27.patch | 451 bytes | kvantstudio |
| #20 | paragraphs-use-drupal-dialog-3028468-20.patch | 12.1 KB | sasanikolic |
| #20 | interfdiff-3028468-18-20.txt | 435 bytes | sasanikolic |
| #18 | paragraphs-use-drupal-dialog-3028468-18.patch | 12.1 KB | pivica |
| #18 | interfdiff-3028468-14-18.txt | 1.72 KB | pivica |
Comments
Comment #2
mike.mcdonald commentedHere is a patch that attempts to implement this feature request
Comment #3
mike.mcdonald commentedComment #5
mike.mcdonald commentedAfter some more experimentation with the failed tests, I can see the reliance on jQuery's base dialog's destroy function. Closing this issue in response.
Comment #6
pivica commentedHad a quick discussion with @miro_dietiker about this. We are not 100% sure but it does make sense that we should use Drupal Dialog API instead of jQuery dialog directly.
It seems that we have a dependency to destroy jQuery dialog and that's not available in the Drupal replacement and that is maybe a reason why paragraphs is using jQuery dialog directly instead of going over Drupal API.
It's worth to investigate this more and figure can we switch to Drupal Dialog API. Re-opening the issue.
Comment #7
mbovan commentedThis fixes a problem where the modal window did not close properly.
I think we have to call
close()function in order to trigger all the events that Drupal dialog implemenation invokes.Comment #8
pivica commentedWill check this a bit.
Comment #9
pivica commentedHere is a new patch based on #7 that
- Cleans/improve code a bit,
- Adds a lot of comments explaining what is going on,
- Fix multiple initializations of .field-add-more-submit elements on each dialog open,
- Enables draggable again when using Drupal Dialog API.
Comment #10
pivica commentedComment #11
pivica commentedNew patch, changes:
- Converted from custom close jQuery UI dialog callback to dialog:afterclose event,
- Fixed issue with core dialog.ajax.js removing .paragraphs-add-dialog element in some cases,
- Various fixes and code cleanup in paragraphs.add_above_button.js file. The most important fix is that behaviour is not running all the time and attaching events.
Comment #12
mbovan commentedThis seems the tests are failing and this seems to be affecting the nested Paragraphs too.
Steps to reproduce:
- Add a nested paragraph via a modal
- Use "Add above" on the container/nested paragraph to add a new paragraph above the container
- There are 2 dialogues present.
Comment #13
pivica commented> and this seems to be affecting the nested Paragraphs too.
A new patch should fix this. Let's check what tests are reporting now.
Comment #14
mbovan commentedThis should fix the tests from #13 in
Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsExperimentalWidgetElementsTest.However, I think the test fail in
Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsExperimentalAddWidgetTestis an actual bug.Steps to reproduce the bug:
Expected behavior:
Comment #15
miro_dietikerI‘m confused here.
If you cancel an „add before“ operation then the next regular add should add at the regular end position. Not before anything. Why should this be a bug?
Comment #16
mbovan commentedI agree.
"Steps to reproduce" in #14 are the steps to reproduce the bug. I edited comment #14 to make it clear.
Comment #17
mbovan commentedSettings to "Needs work" to address #14.
The other two test fails are going to be fixed after #3109279: Fix entity usage assertions in ParagraphsLibraryItemTest fails.
Comment #18
pivica commented> Settings to "Needs work" to address #14.
Should be fixed now.
Comment #19
sasanikolic commentedOne extra * here.
Can this be done in a preprocess or somewhere else? Creating form elements, especially with fixed class names like that with js is a bad practice imho. Maybe a followup since it's not so much related to this ticket.
Comment #20
sasanikolic commentedFixed the nitpick here. Apart from the 2. comment above, looks good to me.
Comment #21
pivica commented> Can this be done in a preprocess or somewhere else?
Probably, i don't really remember why this part is in JS. But definitely this is a separate follow-up issue if we want to improve this, @miro_dietiker?
Comment #22
pivica commentedNo new feedback for latest patch, let's try to commit this.
Comment #24
berdirGoing to trust you guys here, don't make me regret that :p
I did ignore one change in paragraphs.libraries.yml that's just formatting on a part that we'll remove soon.
Comment #25
lendudeJust FYI: this broke our test suite when we tried to add paragraphs in DTT tests. We needed to replicate the logic change that was done to the JS tests in this patch to get it back to green.
Comment #27
kvantstudio commentedThe fix is not compatible with Drupal 9.1 with the Claro admin theme. See https://www.drupal.org/project/drupal/issues/3191527
Comment #28
bnjmnmThe patch in #27 is pretty much guaranteed not to land because
Create a new issue with an issue summary describing what the patch is intended to address, and there’s an actual chance it will land. If this is just here so the patch is available to composer, it’s better to add the patch to a gist instead of adding noise a closed issue where it is out of scope.
Comment #29
lendudeCreated a new issue for this, posted the patch there, #3221429: Enable autoResize for paragraphs modal