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

Use a layout processor rather than plugin in the "Customize the view of a checkout step" docs #8373

Merged
merged 3 commits into from
Jan 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions src/guides/v2.3/howdoi/checkout/checkout_customize.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,44 @@ To disable the component in your `checkout_index_index.xml` use the following in

## Remove a component {#remove}

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.
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
the `\Magento\Checkout\Block\Checkout\LayoutProcessorInterface` interface, and thus a `LayoutProcessorInterface::process($jsLayout)` method.

```php
<?php

namespace <Vendor>\<Module>\Block\Checkout;

use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;

class OurLayoutProcessor implements LayoutProcessorInterface
{
/**
* @param array $jsLayout
* @return array
*/
public function process($jsLayout)
{
//%path_to_target_node% is the path to the component's node in checkout_index_index.
unset($jsLayout['components']['checkout']['children']['steps'][%path_to_target_node%]);
return $jsLayout;
}
}
```

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

```php?start_inline=1
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
return $jsLayout;
```xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Block\Onepage">
<arguments>
<argument name="layoutProcessors" xsi:type="array">
<item name="ourLayoutProcessor" xsi:type="object"><Vendor>\<Module>\Block\Checkout\OurLayoutProcessor</item>
</argument>
</arguments>
</type>
</config>
```

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