10
10
11
11
use Magento \Framework \App \Config \ScopeConfigInterface ;
12
12
use Magento \Framework \Message \ManagerInterface ;
13
+ use Magento \Framework \Message \MessageInterface ;
13
14
use Magento \Framework \Validation \ValidationException ;
14
15
use Magento \Framework \Validator \HTML \WYSIWYGValidatorInterface ;
15
16
use Psr \Log \LoggerInterface ;
17
+ use Magento \Framework \Message \Factory as MessageFactory ;
16
18
17
19
/**
18
20
* Processes backend validator results.
@@ -41,22 +43,30 @@ class Validator implements WYSIWYGValidatorInterface
41
43
*/
42
44
private $ logger ;
43
45
46
+ /**
47
+ * @var MessageFactory
48
+ */
49
+ private $ messageFactory ;
50
+
44
51
/**
45
52
* @param WYSIWYGValidatorInterface $validator
46
53
* @param ManagerInterface $messages
47
54
* @param ScopeConfigInterface $config
48
55
* @param LoggerInterface $logger
56
+ * @param MessageFactory $messageFactory
49
57
*/
50
58
public function __construct (
51
59
WYSIWYGValidatorInterface $ validator ,
52
60
ManagerInterface $ messages ,
53
61
ScopeConfigInterface $ config ,
54
- LoggerInterface $ logger
62
+ LoggerInterface $ logger ,
63
+ MessageFactory $ messageFactory
55
64
) {
56
65
$ this ->validator = $ validator ;
57
66
$ this ->messages = $ messages ;
58
67
$ this ->config = $ config ;
59
68
$ this ->logger = $ logger ;
69
+ $ this ->messageFactory = $ messageFactory ;
60
70
}
61
71
62
72
/**
@@ -71,18 +81,30 @@ public function validate(string $content): void
71
81
if ($ throwException ) {
72
82
throw $ exception ;
73
83
} else {
74
- $ this ->messages ->addWarningMessage (
75
- __ (
76
- 'Temporarily allowed to save HTML value that contains restricted elements. %1 ' ,
77
- $ exception ->getMessage ()
78
- )
84
+ $ this ->messages ->addUniqueMessages (
85
+ [
86
+ $ this ->messageFactory ->create (
87
+ MessageInterface::TYPE_WARNING ,
88
+ (string )__ (
89
+ 'Temporarily allowed to save HTML value that contains restricted elements. %1 ' ,
90
+ $ exception ->getMessage ()
91
+ )
92
+ )
93
+ ]
79
94
);
80
95
}
81
96
} catch (\Throwable $ exception ) {
82
97
if ($ throwException ) {
83
98
throw $ exception ;
84
99
} else {
85
- $ this ->messages ->addWarningMessage (__ ('Invalid HTML provided ' )->render ());
100
+ $ this ->messages ->addUniqueMessages (
101
+ [
102
+ $ this ->messageFactory ->create (
103
+ MessageInterface::TYPE_WARNING ,
104
+ (string )__ ('Invalid HTML provided ' )
105
+ )
106
+ ]
107
+ );
86
108
$ this ->logger ->error ($ exception );
87
109
}
88
110
}
0 commit comments