Skip to content

Commit f615b62

Browse files
authored
Merge pull request #85 from sivaschenko/patch-1
Proposal: Allow class attribute for referenceBlock type in layout xml
2 parents 1eb9d9d + ea59efa commit f615b62

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Allow class attribute for referenceBlock type in layout xml
2+
3+
## Problem
4+
5+
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).
6+
7+
Currently available block class substitution approaches do not resolve the problem:
8+
9+
| Currently available approach | Why the approach does not resolve the problem |
10+
| --------------------------------------------------------------------------------- |:----------------------------------------------:|
11+
| Introduce a preference for block class in di.xml | Block is substituted globally, not only on the desired page |
12+
| Remove the existing block from the layout and declare a new one | Layout configuration related to this block is lost |
13+
| Use plugins | Block functionality is affected for all instances, not only on the desired page |
14+
| 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 |
15+
16+
## Solution
17+
18+
Allow the `class` attribute of `blockReferenceType` in `lib/internal/Magento/Framework/View/Layout/etc/elements.xsd`
19+
20+
See: https://github.com/magento/magento2/pull/18933
21+
22+
### Pros
23+
24+
* Possible to substitute a block class for a specific page easily and in declarative way preserving layout configuration of the block
25+
26+
### Cons
27+
28+
* Allows developer to substitute a block class with a class that is not compatible with a template
29+
30+
## POC
31+
32+
POC is implemented in public pull reqeust: https://github.com/magento/magento2/pull/18933

0 commit comments

Comments
 (0)