CRM_Core_Resources - Allow container to swap the implementation #12959
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.
Overview
CRM_Core_Resources
manages the registration of page-level resources, such as JS and CSS files. This changes the construction logic so that it becomes possible for an extension to modify the definition ofCRM_Core_Resources
.This is intended to allow experimentation with theme-management in extensions.
Before and After (Unchanged)
CRM_Core_Resources::singleton()
,Civi::resources()
, andCivi::container()->get('resources')
all return the same object.Before
The object construction is handled in the
singleton()
function.After
The object construction is handled in the
Container
. Container defintions can be modified viahook_civicrm_container
.Technical Details
A possible critique: "You can't move everything in the container; is this one safe?." The main limitation of the container is that it cannot initialize boot-critical services (i.e. it's not available during pre/early-bootstrap). However, the resource manager is not boot-critical. You can tell this because the old logic (from
CRM_Core_Resources::singleton()
) already relied on having a working container (to lookupjs_strings
). If it was boot-critical, then the old call toCivi::cache('js_strings')
would have been crash-y.