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.

Comments

mike.mcdonald created an issue. See original summary.

mike.mcdonald’s picture

StatusFileSize
new3.55 KB

Here is a patch that attempts to implement this feature request

mike.mcdonald’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 3028468_use_drupal_dialog.patch, failed testing. View results

mike.mcdonald’s picture

Status: Needs work » Closed (works as designed)

After 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.

pivica’s picture

Status: Closed (works as designed) » Active

Had 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.

mbovan’s picture

Status: Active » Needs review
StatusFileSize
new2.17 KB
new2.56 KB

This 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.

pivica’s picture

Assigned: Unassigned » pivica

Will check this a bit.

pivica’s picture

Issue tags: +ContributionWeekend2020, +ContributionWeekendCH
StatusFileSize
new3.76 KB
new4.68 KB

Here 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.

pivica’s picture

Status: Needs review » Needs work
pivica’s picture

Assigned: pivica » Unassigned
Status: Needs work » Needs review
StatusFileSize
new5.77 KB
new8.03 KB

New 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.

mbovan’s picture

Status: Needs review » Needs work

This 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.

pivica’s picture

Status: Needs work » Needs review
StatusFileSize
new631 bytes
new8.04 KB

> and this seems to be affecting the nested Paragraphs too.

A new patch should fix this. Let's check what tests are reporting now.

mbovan’s picture

StatusFileSize
new12.07 KB
new4.03 KB

This should fix the tests from #13 in Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsExperimentalWidgetElementsTest.

However, I think the test fail in Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsExperimentalAddWidgetTest is an actual bug.

Steps to reproduce the bug:

  1. Add a new node
  2. Add a text paragraph
  3. Click Add above on the text paragraph action and close it
  4. Click the main Add Paragraph field on the node and add a user paragraph
  5. The user paragraph was inserted before the text paragraph.

Expected behavior:

  1. Add a new node
  2. Add a text paragraph
  3. Click Add above on the text paragraph action and close it
  4. Click the main Add Paragraph field on the node and add a user paragraph
  5. The user paragraph was inserted after the text paragraph.
miro_dietiker’s picture

I‘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?

mbovan’s picture

I agree.

"Steps to reproduce" in #14 are the steps to reproduce the bug. I edited comment #14 to make it clear.

mbovan’s picture

Status: Needs review » Needs work

Settings 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.

pivica’s picture

Status: Needs work » Needs review
StatusFileSize
new1.72 KB
new12.1 KB

> Settings to "Needs work" to address #14.

Should be fixed now.

sasanikolic’s picture

Status: Needs review » Needs work
  1. +++ b/js/paragraphs.add_above_button.js
    @@ -8,44 +8,44 @@
    +   * * @type {Drupal~behavior}
    

    One extra * here.

  2. +++ b/js/paragraphs.add_above_button.js
    @@ -8,44 +8,44 @@
    +          var $button = $('<input class="paragraphs-dropdown-action paragraphs-dropdown-action--add-above button js-form-submit form-submit" type="submit" value="' + Drupal.t('Add above') + '">');
    

    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.

sasanikolic’s picture

Status: Needs work » Needs review
StatusFileSize
new435 bytes
new12.1 KB

Fixed the nitpick here. Apart from the 2. comment above, looks good to me.

pivica’s picture

> 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?

pivica’s picture

Status: Needs review » Reviewed & tested by the community

No new feedback for latest patch, let's try to commit this.

  • Berdir committed f5d7954 on 8.x-1.x authored by sasanikolic
    Issue #3028468 by pivica, mbovan, sasanikolic, mike.mcdonald: Use Drupal...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Going 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.

lendude’s picture

Just 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

kvantstudio’s picture

StatusFileSize
new451 bytes

The fix is not compatible with Drupal 9.1 with the Claro admin theme. See https://www.drupal.org/project/drupal/issues/3191527

bnjmnm’s picture

The patch in #27 is pretty much guaranteed not to land because

  • This issue has been closed for over a year
  • It’s not a change that is in scope with the requirements specified in the issue summary, it just happens to touch on code that was also touched here

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.

lendude’s picture

Created a new issue for this, posted the patch there, #3221429: Enable autoResize for paragraphs modal