Skip to content
Closed
Show file tree
Hide file tree
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
38 changes: 38 additions & 0 deletions ReCaptchaContact/Model/WebapiConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Magento\ReCaptchaContact\Model;

use Magento\ContactGraphQl\Model\Resolver\ContactUs;
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
use Magento\ReCaptchaUi\Model\ValidationConfigResolverInterface;
use Magento\ReCaptchaValidationApi\Api\Data\ValidationConfigInterface;
use Magento\ReCaptchaWebapiApi\Api\Data\EndpointInterface;
use Magento\ReCaptchaWebapiApi\Api\WebapiValidationConfigProviderInterface;

class WebapiConfigProvider implements WebapiValidationConfigProviderInterface
{
private const CAPTCHA_ID = 'contact';

public function __construct(
private readonly IsCaptchaEnabledInterface $isCaptchaEnabled,
private readonly ValidationConfigResolverInterface $configResolver
) {
}

/**
* @inheritDoc
*/
public function getConfigFor(EndpointInterface $endpoint): ?ValidationConfigInterface
{
if ($endpoint->getServiceMethod() === 'resolve'
&& $endpoint->getServiceClass() === ContactUs::class) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see in other places we have a || here. are you sure it should be &&?
Example: https://github.com/magento/security-package/blob/develop/ReCaptchaCustomer/Model/WebapiConfigProvider.php#L65-L69

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ihor-sviziev After the research, I found out that \Magento\ReCaptchaSendFriend\Model\WebapiConfigProvider::getConfigFor is the most in-line with Contact form, that's why it's && not ||

if ($this->isCaptchaEnabled->isCaptchaEnabledFor(self::CAPTCHA_ID)) {
return $this->configResolver->get(self::CAPTCHA_ID);
}
}

return null;
}
}
11 changes: 11 additions & 0 deletions ReCaptchaContact/etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?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\ReCaptchaWebapiApi\Model\CompositeWebapiValidationConfigProvider">
<arguments>
<argument name="providers" xsi:type="array">
<item name="contact" xsi:type="object">Magento\ReCaptchaContact\Model\WebapiConfigProvider</item>
</argument>
</arguments>
</type>
</config>