Problem/Motivation
ConfigEntityBase provides three methods to help with dependency management:
- calculateDependencies()
- addDependency()
- addDependencies()
In #2248151: Configurable plugins can not control instance-specific config dependencies we added a mechanism for configurable plugins to manage their own dependencies.
However, unlike entities that had these convenience methods, plugins were left to manipulate the data structures directly.
Furthermore, if other objects need to calculate the dependencies of any plugins they manage, they would need to copy the logic used in ConfigEntityBase::calculateDependencies()
Proposed resolution
Move these methods into two traits:
One for addDependency()/addDependencies() for the data structure manipulation
One with a method called calculatePluginDependencies() just for the plugin-specific parts.
Remaining tasks
N/A
User interface changes
N/A
API changes
New traits available. No actual API change.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | plugin-dependency-2266859-1.patch | 9.03 KB | tim.plunkett |
Comments
Comment #1
tim.plunkettComment #2
tim.plunkettBecause we want to do this entity-specific check before adding dependencies, we need to do this aliasing trick with traits.
We have no standard way to document this pattern, but while it seems weird now, it will become more common as we become more familiar with traits.
When I added this code to user roles initially, I remember being very confused about the nesting of the dependencies. This method makes it that much easier
Comment #3
alexpottThis makes me +1 to this approach. Same methods for plugins and config entities is really nice and consistent - and if we need to extend this to anything else in the future (content entities???) it'll be nice.
Comment #4
dawehnerI wonder whether we should have a dedicated test for this trait, but beside from this this seems fine.
Comment #5
wim leersYes — much, much better :)
Comment #6
webchickCommitted and pushed to 8.x. Thanks!
Comment #8
les limFYI, this patch made D8 incompatible with APC 3.1.9, which is the latest stable version and the one packaged with MAMP 2. I don't think that's anything we should code around, but made a note of it at https://drupal.org/requirements/php.
Comment #9
tim.plunkett