|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\ReCaptchaStorePickup\Block\LayoutProcessor\Checkout; |
| 9 | + |
| 10 | +use Magento\Checkout\Block\Checkout\LayoutProcessorInterface; |
| 11 | +use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface; |
| 12 | +use Magento\ReCaptchaUi\Model\UiConfigResolverInterface; |
| 13 | + |
| 14 | +/** |
| 15 | + * Provides reCaptcha component configuration. |
| 16 | + */ |
| 17 | +class Onepage implements LayoutProcessorInterface |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var UiConfigResolverInterface |
| 21 | + */ |
| 22 | + private $captchaUiConfigResolver; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var IsCaptchaEnabledInterface |
| 26 | + */ |
| 27 | + private $isCaptchaEnabled; |
| 28 | + |
| 29 | + /** |
| 30 | + * @param UiConfigResolverInterface $captchaUiConfigResolver |
| 31 | + * @param IsCaptchaEnabledInterface $isCaptchaEnabled |
| 32 | + */ |
| 33 | + public function __construct( |
| 34 | + UiConfigResolverInterface $captchaUiConfigResolver, |
| 35 | + IsCaptchaEnabledInterface $isCaptchaEnabled |
| 36 | + ) { |
| 37 | + $this->captchaUiConfigResolver = $captchaUiConfigResolver; |
| 38 | + $this->isCaptchaEnabled = $isCaptchaEnabled; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @inheritdoc |
| 43 | + */ |
| 44 | + public function process($jsLayout) |
| 45 | + { |
| 46 | + $key = 'customer_login'; |
| 47 | + if ($this->isCaptchaEnabled->isCaptchaEnabledFor($key)) { |
| 48 | + $jsLayout['components']['checkout']['children']['steps']['children']['store-pickup']['children'] |
| 49 | + ['store-selector']['children']['customer-email']['children']['additional-login-form-fields']['children'] |
| 50 | + ['recaptcha']['settings'] = $this->captchaUiConfigResolver->get($key); |
| 51 | + } else { |
| 52 | + if (isset($jsLayout['components']['checkout']['children']['steps']['children']['store-pickup']['children'] |
| 53 | + ['store-selector']['children']['customer-email']['children']['additional-login-form-fields']['children'] |
| 54 | + ['recaptcha']['settings'])) { |
| 55 | + unset($jsLayout['components']['checkout']['children']['steps']['children']['store-pickup']['children'] |
| 56 | + ['store-selector']['children']['customer-email']['children']['additional-login-form-fields']['children'] |
| 57 | + ['recaptcha']['settings']); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + return $jsLayout; |
| 62 | + } |
| 63 | +} |
0 commit comments