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 all commits
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
45 changes: 38 additions & 7 deletions src/guides/v2.3/howdoi/checkout/checkout_customize.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,47 @@ 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.
To keep a component from being rendered, 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, 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.
To use this sample in your code, replace the `%path_to_target_node%` placeholder with real value.

{:.bs-callout-info}
Disable vs remove a component: If you disable a component, it is loaded but not rendered. If you remove a component, it is removed and not loaded.
Disable vs remove a component: A disabled component is loaded but not rendered. If you remove a component, it is removed and not loaded.