Skip to main content
added 1 character in body
Source Link
Mrweiner
  • 2k
  • 4
  • 26
  • 49

Since Drupal behaviors are really just javascript objects, all you need to do is to ensure that the behavior you're overwriting is loaded before your replacement. So:

my_module.libraries.yml

some_new_lib:
  js:
    my-js-file.js: {}
  dependencies:
    - libary_with/behavior_you_want_to_override
    - core/jquery //  # anything else you need

my-js.file

(function ($) {

  Drupal.behaviors.nameOfBehaviorYouWantToOverride = {
    // Your little dash of magic
  }

})(jQuery);

Since Drupal behaviors are really just javascript objects, all you need to do is to ensure that the behavior you're overwriting is loaded before your replacement. So:

my_module.libraries.yml

some_new_lib:
  js:
    my-js-file.js: {}
  dependencies:
    - libary_with/behavior_you_want_to_override
    - core/jquery // anything else you need

my-js.file

(function ($) {

  Drupal.behaviors.nameOfBehaviorYouWantToOverride = {
    // Your little dash of magic
  }

})(jQuery);

Since Drupal behaviors are really just javascript objects, all you need to do is to ensure that the behavior you're overwriting is loaded before your replacement. So:

my_module.libraries.yml

some_new_lib:
  js:
    my-js-file.js: {}
  dependencies:
    - libary_with/behavior_you_want_to_override
    - core/jquery   # anything else you need

my-js.file

(function ($) {

  Drupal.behaviors.nameOfBehaviorYouWantToOverride = {
    // Your little dash of magic
  }

})(jQuery);
Source Link
Mrweiner
  • 2k
  • 4
  • 26
  • 49

Since Drupal behaviors are really just javascript objects, all you need to do is to ensure that the behavior you're overwriting is loaded before your replacement. So:

my_module.libraries.yml

some_new_lib:
  js:
    my-js-file.js: {}
  dependencies:
    - libary_with/behavior_you_want_to_override
    - core/jquery // anything else you need

my-js.file

(function ($) {

  Drupal.behaviors.nameOfBehaviorYouWantToOverride = {
    // Your little dash of magic
  }

})(jQuery);