Skip to content

Commit

Permalink
Merge pull request #85 from sivaschenko/patch-1
Browse files Browse the repository at this point in the history
Proposal: Allow class attribute for referenceBlock type in layout xml
  • Loading branch information
buskamuza authored Mar 25, 2019
2 parents 1eb9d9d + ea59efa commit f615b62
Showing 1 changed file with 32 additions and 0 deletions.
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

0 comments on commit f615b62

Please sign in to comment.