(REF) Make it easier for extensions to define basic bundles #18660
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
#18247 (same dev-cycle, 5.31.alpha1) allows one to define resource bundles. This improves developer experience, requiring a bit less boilerplate/duplication.
Before
To define a new bundle, one implements
hook_container
and creates a factory function.Note that the factory function
_mymodule_create_mybundle
has some boilerplate aroundalterBundle()
anduseRegion()
. It's important to include these to ensure that the bundle is modifiable.After
You still create a definition, but the definition can use the pre-written function
createBasicBundle
:Optionally, if you want to initialize the default content, you can still use a factory function - but it doesn't have to have the boilerplate. Note how
_mymodule_init_mybundle
is simpler than_mymodule_create_mybundle
:Comments
I marked it as (REF) because it's still backward compatible and not visible to an end-user. The simplification only applies if you use
createBasicBundle
. Any existing bundles (like the bootstrap3 bundle) can still work as before. Additionally, note that this is refining something recently added in the same dev-cycle (5.31-alpah1).I'd like to get this merged before 5.31-beta1 so that we can use the cleaner notation in the docs.