1010
1111use Magento \Framework \App \Config \ScopeConfigInterface ;
1212use Magento \Framework \Message \ManagerInterface ;
13+ use Magento \Framework \Message \MessageInterface ;
1314use Magento \Framework \Validation \ValidationException ;
1415use Magento \Framework \Validator \HTML \WYSIWYGValidatorInterface ;
1516use Psr \Log \LoggerInterface ;
17+ use Magento \Framework \Message \Factory as MessageFactory ;
1618
1719/**
1820 * Processes backend validator results.
@@ -41,22 +43,30 @@ class Validator implements WYSIWYGValidatorInterface
4143 */
4244 private $ logger ;
4345
46+ /**
47+ * @var MessageFactory
48+ */
49+ private $ messageFactory ;
50+
4451 /**
4552 * @param WYSIWYGValidatorInterface $validator
4653 * @param ManagerInterface $messages
4754 * @param ScopeConfigInterface $config
4855 * @param LoggerInterface $logger
56+ * @param MessageFactory $messageFactory
4957 */
5058 public function __construct (
5159 WYSIWYGValidatorInterface $ validator ,
5260 ManagerInterface $ messages ,
5361 ScopeConfigInterface $ config ,
54- LoggerInterface $ logger
62+ LoggerInterface $ logger ,
63+ MessageFactory $ messageFactory
5564 ) {
5665 $ this ->validator = $ validator ;
5766 $ this ->messages = $ messages ;
5867 $ this ->config = $ config ;
5968 $ this ->logger = $ logger ;
69+ $ this ->messageFactory = $ messageFactory ;
6070 }
6171
6272 /**
@@ -71,18 +81,30 @@ public function validate(string $content): void
7181 if ($ throwException ) {
7282 throw $ exception ;
7383 } 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+ ]
7994 );
8095 }
8196 } catch (\Throwable $ exception ) {
8297 if ($ throwException ) {
8398 throw $ exception ;
8499 } 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+ );
86108 $ this ->logger ->error ($ exception );
87109 }
88110 }
0 commit comments