Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 3aa70ef

Browse files
author
Julian van den Berkmortel
committed
Use a layout processor rather than plugin in the "Customize the view of a checkout step" docs
1 parent 1a5af52 commit 3aa70ef

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/guides/v2.3/howdoi/checkout/checkout_customize.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,44 @@ To disable the component in your `checkout_index_index.xml` use the following in
154154

155155
## Remove a component {#remove}
156156

157-
To remove a component from layout rendering, you need to create a [plugin]({{ page.baseurl }}/extension-dev-guide/plugins.html) for the `\Magento\Checkout\Block\Checkout\LayoutProcessor::process` method. In your plugin, implement the around method removing the corresponding layout nodes at run-time.
157+
If you want to keep a component from being rendered, you need to create a layout processor. A layout processor consists of a class, implementing
158+
the `\Magento\Checkout\Block\Checkout\LayoutProcessorInterface` interface, and thus a `LayoutProcessorInterface::process($jsLayout)` method.
159+
160+
```php
161+
<?php
162+
163+
namespace <Vendor>\<Module>\Block\Checkout;
164+
165+
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
166+
167+
class OurLayoutProcessor implements LayoutProcessorInterface
168+
{
169+
/**
170+
* @param array $jsLayout
171+
* @return array
172+
*/
173+
public function process($jsLayout)
174+
{
175+
//%path_to_target_node% is the path to the component's node in checkout_index_index.
176+
unset($jsLayout['components']['checkout']['children']['steps'][%path_to_target_node%]);
177+
return $jsLayout;
178+
}
179+
}
180+
```
158181

159-
The following sample is an example of the around method removing a component:
182+
Once created you can add the layout processor through Dependency Injection (DI).
160183

161-
```php?start_inline=1
162-
unset($jsLayout['components']['checkout']['children']['steps'][%path_to_target_node%]); //%path_to_target_node% is the path to the component's node in checkout_index_index.xml
163-
return $jsLayout;
184+
```xml
185+
<?xml version="1.0"?>
186+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
187+
<type name="Magento\Checkout\Block\Onepage">
188+
<arguments>
189+
<argument name="layoutProcessors" xsi:type="array">
190+
<item name="ourLayoutProcessor" xsi:type="object"><Vendor>\<Module>\Block\Checkout\OurLayoutProcessor</item>
191+
</argument>
192+
</arguments>
193+
</type>
194+
</config>
164195
```
165196

166197
If you want to use this sample in your code, replace the `%path_to_target_node%` placeholder with real value.

0 commit comments

Comments
 (0)