Allow users to override plugin handler priorities #2165
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Not sure how pressing this is, but I've seen it once or twice on the forums, and it seems easy enough to fix.
Most plugin authors leave the priority of their listeners at 0 unless there is some internal reason to tweak them. But no plugin author can predict what sorts of interactions may exist with all other plugins. If a user discovers that they need certain plugins to run before others, the only current way to change that is by modifying the priorities in the plugin's
.php
file. Which will get clobbered every time the plugin is updated.This PR allows users to create a
user/config/priorities.yaml
file that may contain the following data:The PR replaces the ternary if/else statement in
Grav\Common\Plugin::enable
with a new functiongetPriority
that now has three possibilities instead of two:priorities.yaml
, it is returned..php
file, if provided.This is advanced usage that still requires users to do some digging to find the listeners that need adjusting. This PR is backwards compatible unless there's some other use for
user/config/priorities.yaml
that I'm not aware of. It does appear to work with plugins with hyphens in their names.I will draft up a PR to
grav-learn
to match this approach. If implemented, I can see someone developing an admin plugin to make it really easy to make these adjustments.This is only one approach. There may be very good reasons why this approach doesn't work. I'm open to any feedback. I don't know how to test the effect my changes have on performance. I'm open to instruction.