Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The Drupal.behaviors.fluidModal will attach it events every time behaviours are run on the page. Among other things, this will produce multiple callbacks to Drupal.entityBrowserModal.fluidDialog.
Proposed resolution
Attach Drupal.behaviors.fluidModal events only ones per document/iframe.
Comment | File | Size | Author |
---|---|---|---|
#10 | with patch applied.png | 13.89 KB | oknate |
#9 | multiple firings.png | 14.39 KB | oknate |
#6 | entity-browser-behaviours-run-once-3055370-6.patch | 982 bytes | pivica |
#4 | actual entity browser display with the patch.png | 275.28 KB | sasanikolic |
#4 | expected entity browser display.png | 541.36 KB | sasanikolic |
Comments
Comment #2
pivica CreditAttribution: pivica at MD Systems GmbH commentedHere is the first patch for this.
There is probably a similar problem with Drupal.behaviors.entityBrowserModal - that code will run on each behaviour trigger but I don't have time right now to check it.
Comment #3
oknateThanks, I'll take a look as soon as possible.
Comment #4
sasanikolic CreditAttribution: sasanikolic commentedThis definition is causing some trouble in one of our projects. Not sure why, but the $document is not set correctly and the call
$document.on('dialogopen', '.ui-dialog',...
does not get executed, hence the height of the entity browser does not get set. If I change $document to $(document) on that call it works fine.See the expected vs actual images attached.
Comment #5
sasanikolic CreditAttribution: sasanikolic commentedComment #6
pivica CreditAttribution: pivica at MD Systems GmbH commentedTook a new look into this after this bug and, hmmm, it seems i messed a stuff a bit. The idea is good, but execution not that good ;)
On top of this, it seems when the behaviour context is an iframe then `context.contentDocument.defaultView` will sometimes be set but sometimes it will be null so we can not use it in this case.
But after taking a second look on this, really there is no point using context to get a document and then use it. What we need is to always operate on the window which is a global object and its document, because here we need to do `once('fluid-modal')` check. The rest is not important.
Here is a new patch which should hopefully work now.
One more thing, i've noticed we could use https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimation... inside $window.resize() to optimize things even more, but that should be a follow-up.
Comment #7
sasanikolic CreditAttribution: sasanikolic commentedAgree that the context was a bit of a messup.
Tested locally and works fine, thanks for fixing @pivica.
Comment #8
oknateThanks, I'll review ASAP.
Comment #9
oknateManually testing, it's easy to see it fires multiple times. On a clean install, if you enable the entity_browser_example module:
It fires for each of the fields, so it shows in the console it fires seven times.
and the events fire six times when opening the dialog:
Comment #10
oknateWith patch applied, the events fire only once each.
Comment #13
oknateCommitted, thanks.