1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. |
4
|
|
|
* @author: <mailto:[email protected]> |
5
|
|
|
* @github: <https://github.com/hryvinskyi> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Hryvinskyi\InvisibleCaptcha\Plugin\Block\Account; |
9
|
|
|
|
10
|
|
|
use Hryvinskyi\Base\Helper\Json; |
11
|
|
|
use Hryvinskyi\InvisibleCaptcha\Helper\Config\Frontend; |
12
|
|
|
use Hryvinskyi\InvisibleCaptcha\Helper\Config\General; |
13
|
|
|
use Hryvinskyi\InvisibleCaptcha\Model\LayoutSettings; |
14
|
|
|
use Magento\Customer\Block\Account\AuthenticationPopup; |
15
|
|
|
|
16
|
|
|
class AuthenticationPopupPlugin |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var LayoutSettings |
20
|
|
|
*/ |
21
|
|
|
private $layoutSettings; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var General |
25
|
|
|
*/ |
26
|
|
|
private $generalConfig; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Frontend |
30
|
|
|
*/ |
31
|
|
|
private $frontendConfig; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* AuthenticationPopupPlugin constructor. |
35
|
|
|
* |
36
|
|
|
* @param LayoutSettings $layoutSettings |
37
|
|
|
* @param General $generalConfig |
38
|
|
|
* @param Frontend $frontendConfig |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
LayoutSettings $layoutSettings, |
42
|
|
|
General $generalConfig, |
43
|
|
|
Frontend $frontendConfig |
44
|
|
|
) { |
45
|
|
|
$this->layoutSettings = $layoutSettings; |
46
|
|
|
$this->generalConfig = $generalConfig; |
47
|
|
|
$this->frontendConfig = $frontendConfig; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param AuthenticationPopup $subject |
52
|
|
|
* @param string $result |
53
|
|
|
* |
54
|
|
|
* @return string |
55
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
56
|
|
|
*/ |
57
|
|
|
public function afterGetJsLayout(AuthenticationPopup $subject, $result) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$layout = Json::decode($result); |
60
|
|
|
$layout['components']['authenticationPopup']['children']['invisible-captcha']['config'] |
61
|
|
|
= $this->layoutSettings->getCaptchaSettings(); |
62
|
|
|
|
63
|
|
|
if ( |
64
|
|
|
( |
65
|
|
|
!$this->generalConfig->hasEnabled() |
66
|
|
|
|| !$this->frontendConfig->hasEnabled() |
67
|
|
|
|| !$this->frontendConfig->hasEnabledCustomerLogin() |
68
|
|
|
) |
69
|
|
|
&& isset($layout['components']['authenticationPopup']['children']['invisible-captcha']) |
70
|
|
|
) { |
71
|
|
|
unset($layout['components']['authenticationPopup']['children']['invisible-captcha']); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return Json::encode($layout); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.