9
9
10
10
use Magento \AdminAdobeIms \Model \ImsConnection ;
11
11
use Magento \Framework \Exception \InvalidArgumentException ;
12
+ use Magento \Framework \Message \ManagerInterface as MessageManagerInterface ;
12
13
use Magento \Framework \View \Element \Block \ArgumentInterface ;
14
+ use Psr \Log \LoggerInterface ;
13
15
14
16
class LinkViewModel implements ArgumentInterface
15
17
{
16
- /** @var string */
17
- private string $ authUrl ;
18
+ /**
19
+ * @var string|null
20
+ */
21
+ private ?string $ authUrl ;
22
+
23
+ /**
24
+ * @var LoggerInterface
25
+ */
26
+ private LoggerInterface $ logger ;
27
+
28
+ /**
29
+ * @var MessageManagerInterface
30
+ */
31
+ private MessageManagerInterface $ messageManager ;
18
32
19
33
/**
20
34
* @param ImsConnection $connection
35
+ * @param LoggerInterface $logger
36
+ * @param MessageManagerInterface $messageManager
21
37
*/
22
38
public function __construct (
23
- ImsConnection $ connection
39
+ ImsConnection $ connection ,
40
+ LoggerInterface $ logger ,
41
+ MessageManagerInterface $ messageManager
24
42
) {
43
+ $ this ->logger = $ logger ;
44
+ $ this ->messageManager = $ messageManager ;
45
+
25
46
try {
26
47
$ this ->authUrl = $ connection ->auth ();
27
- } catch (InvalidArgumentException $ exception ) {
28
- $ this ->authUrl = '' ;
48
+ } catch (InvalidArgumentException $ e ) {
49
+ $ this ->logger ->error ($ e ->getMessage ());
50
+ $ this ->authUrl = null ;
51
+ $ this ->addImsErrorMessage (
52
+ 'Could not connect to Adobe IMS. ' ,
53
+ $ e ->getMessage ()
54
+ );
55
+ } catch (\Exception $ e ) {
56
+ $ this ->logger ->error ($ e ->getMessage ());
57
+ $ this ->authUrl = null ;
58
+ $ this ->addImsErrorMessage (
59
+ 'Could not connect to Adobe IMS. ' ,
60
+ 'Something went wrong during Adobe IMS connection check. '
61
+ );
29
62
}
30
63
}
31
64
@@ -42,10 +75,28 @@ public function isActive(): bool
42
75
/**
43
76
* Get authorization URL for Login Button
44
77
*
45
- * @return string
78
+ * @return string|null
46
79
*/
47
- public function getButtonLink (): string
80
+ public function getButtonLink (): ? string
48
81
{
49
82
return $ this ->authUrl ;
50
83
}
84
+
85
+ /**
86
+ * Add Admin Adobe IMS Error Message
87
+ *
88
+ * @param string $headline
89
+ * @param string $message
90
+ * @return void
91
+ */
92
+ private function addImsErrorMessage (string $ headline , string $ message ): void
93
+ {
94
+ $ this ->messageManager ->addComplexErrorMessage (
95
+ 'adminAdobeImsMessage ' ,
96
+ [
97
+ 'headline ' => __ ($ headline )->getText (),
98
+ 'message ' => __ ($ message )->getText ()
99
+ ]
100
+ );
101
+ }
51
102
}
0 commit comments