Problem/Motivation

Sometimes behaviors have to be ordered. This could be done with the change we added in #2367655: Control the list of behaviors run by Drupal.attachBehaviors. Ordering the whole behavior list is not very intuitive when you just have to run the behavior before/after a specific behavior.

Behavior ordering is needed to be able to remove weights from library definitions: #1945262: Replace custom weights with dependencies in library declarations; introduce "before" and "after" for conditional ordering.

Proposed resolution

To make this easier to use we want to add a way to define a list of behaviors that should be ran before or after specific behavior.

Remaining tasks

-

User interface changes

-

API changes

Add a new keys to behavior object:

Drupal.behaviors.newBehavior = {
  attach: function () {},
  detach: function () {},
  before: ['contextual'],
  after: ['toolbar']
};

Comments

nod_’s picture

Wim Leers’s picture

Drupal.behaviors.newBehavior = {
  attach: function () {},
  detach: function () {},
  before: ['contextual'],
  after: ['toolbar']
};

We shouldn't do this, but fix #1945262: Replace custom weights with dependencies in library declarations; introduce "before" and "after" for conditional ordering instead. Then you don't need to specify it in JS, but in the asset library metadata. Because then it'll continue to work when the dependency tree. Specifying this in the JS will not automatically be made aware of additional library dependencies/before/after metadata, but specifying it in the asset library metadata will.

nod_’s picture

Have the before after suff in php based on files then?

I'm fine with it being in PHP. I'm actually a bit worried the whole resolution stuff in the js for before/after is going to require too much code.

Wim Leers’s picture

Yes.

core/drupal depends on core/drupalSettings anyway. So we can pass the relevant asset library ordering information in window.drupalSettings.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.