-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from sivaschenko/patch-1
Proposal: Allow class attribute for referenceBlock type in layout xml
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
design-documents/class-attibute-for-referenceBlock-type-in-layout-xml.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Allow class attribute for referenceBlock type in layout xml | ||
|
||
## Problem | ||
|
||
It is **impossible to substitute a block class** and/or customize block method(s) implementation **on a specific page keeping layout configuration of the block** (position, sorting in the layout, child blocks, arguments). | ||
|
||
Currently available block class substitution approaches do not resolve the problem: | ||
|
||
| Currently available approach | Why the approach does not resolve the problem | | ||
| --------------------------------------------------------------------------------- |:----------------------------------------------:| | ||
| Introduce a preference for block class in di.xml | Block is substituted globally, not only on the desired page | | ||
| Remove the existing block from the layout and declare a new one | Layout configuration related to this block is lost | | ||
| Use plugins | Block functionality is affected for all instances, not only on the desired page | | ||
| Use plugins that change method functionality only for specific page/layout handle | This approach is imperative, implicit, prone to mistakes, bugs and implementation inconsistency, it is not compatible with layout updates | | ||
|
||
## Solution | ||
|
||
Allow the `class` attribute of `blockReferenceType` in `lib/internal/Magento/Framework/View/Layout/etc/elements.xsd` | ||
|
||
See: https://github.com/magento/magento2/pull/18933 | ||
|
||
### Pros | ||
|
||
* Possible to substitute a block class for a specific page easily and in declarative way preserving layout configuration of the block | ||
|
||
### Cons | ||
|
||
* Allows developer to substitute a block class with a class that is not compatible with a template | ||
|
||
## POC | ||
|
||
POC is implemented in public pull reqeust: https://github.com/magento/magento2/pull/18933 |