5

In system.services.yml and many other services files, one can find priorities like this:

services:

  ...

  path_processor.files:
    class: Drupal\system\PathProcessor\PathProcessorFiles
    tags:
      - { name: path_processor_inbound, priority: 200 }

  ...

Are these priorities similar to the weight-system we know from Drupal 7, where a low weight means earlier in the processing order. Or do priorities work the other way around, where the items with the highest priority are processed first?

I am asking because I could not find a source explaining this.

7

Drupal uses the EventDispatcher from Symfony and there the priority is used to control in which order the event listeners are triggered:

An optional priority integer (higher equals more important and therefore that the listener will be triggered earlier) that determines when a listener is triggered versus other listeners (defaults to 0). If two listeners have the same priority, they are executed in the order that they were added to the dispatcher.

So the priority in D8 is exactly the opposite of the weight in D7.

The example you used in the question is not an event subscriber, but it uses the same concept of priorities.

  • Thanks a bunch, I did not think of looking into Symfony's documentation. – Neograph734 Mar 19 '17 at 17:14
  • Weight still exists in Drupal 8 for form/render elements and other things, otherwise correct. – Berdir Mar 19 '17 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.