- Issue created by @ventzie
- Merge request !19Issue #3409418: Remove settings from Drupal.attachBehaviors. → (Open) created by ventzie
- Merge request !20Issue #3409418: Remove settings from Drupal.attachBehaviors. → (Open) created by ventzie
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.
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.
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);
Active
2.0
Code