Control the list of behaviors run by Drupal.attachBehaviors

Created on 1 November 2014, about 10 years ago
Updated 30 January 2023, almost 2 years ago

Comes up periodically that people want to alter the order of behaviors being run or only run a few of them. Instead of modifying Drupal.behaviors object we should have a way of controlling that explicitly (came up in #2362637: Editor.js attach/detach doesn't pass context all the way down ). Having this would mean that the behavior system is justified and Drupal can't use events to do it's thing, see #1446166-39: Use JS events instead of Drupal.behaviors .

Introducing a new parameter, behaviorList, and a new function Drupal.behaviorList.

Drupal.attachBehaviors(document, drupalSettings, ['AJAX', 'editor', 'formUpdated', 'escapeAdmin']);

// Override default behavior ordering
Drupal.behaviorList = function (event, trigger) { return myCustomOrderedBehaviorsArray; };

Same for Drupal.detachBehaviors. behaviorList defaults to the whole list of behaviors. This can also be used to alter the order in which behaviors are run.

Beta phase evaluation

@TODO

📌 Task
Status

Needs work

Version

10.1

Component
Javascript 

Last updated 3 days ago

Created by

🇫🇷France nod_ Lille

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Production build 0.71.5 2024