Problem/Motivation
Drupal.attachBehaviors in entityreference_filter.js should not supply settings parameter since other Drupal.behaviors don't care about its settings. When settings is provided drupalSettings is not set which leads to errors in other Drupal.behaviors functions that rely on drupalSettings like Drupal.behaviors.dialog in dialog.ajax.js.
Steps to reproduce
Use drupal.dialog.ajax library together with entityreference_filter.js.
You will get the following error:
drupal.js?v=10.1.5:64 Uncaught TypeError: Cannot read properties of undefined (reading 'close')
at Object.attach (dialog.ajax.js?v=10.1.5:45:45)
at drupal.js?v=10.1.5:166:24
at Array.forEach ()
at Drupal.attachBehaviors (drupal.js?v=10.1.5:162:34)
at Drupal.AjaxCommands.entityReferenceFilterInsertNoWrapCommand (entityreference_filter.js?v=1.x:157:14)
at ajax.js?v=10.1.5:1034:41
at
const originalClose = settings.dialog.close;
since drupalSettings is not there.
Proposed resolution
settings should be removed from Drupal.attachBehaviors(wrapperEl, settings);
diff --git a/js/entityreference_filter.js b/js/entityreference_filter.js
index dd96650..438ead8 100644
--- a/js/entityreference_filter.js
+++ b/js/entityreference_filter.js
@@ -152,9 +152,7 @@
// successfully added to the page, this if statement allows
// #ajax['wrapper'] to be optional.
if (new_content.parents('html').length > 0) {
- // Apply any settings from the returned JSON if available.
- settings = response.settings || ajax.settings || Drupal.settings;
- Drupal.attachBehaviors(wrapperEl, settings);
+ Drupal.attachBehaviors(wrapperEl);
}
};
})(Drupal, jQuery);
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork entityreference_filter-3409418
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments