17
17
use Magento \Framework \Exception \CouldNotSaveException ;
18
18
use Magento \Framework \Exception \NoSuchEntityException ;
19
19
use Magento \Framework \Reflection \DataObjectProcessor ;
20
- use Magento \Framework \Validation \ValidationException ;
21
- use Magento \Framework \Validator \HTML \WYSIWYGValidatorInterface ;
22
20
use Magento \Store \Model \StoreManagerInterface ;
21
+ use Magento \Framework \EntityManager \HydratorInterface ;
23
22
24
23
/**
25
24
* Class BlockRepository
@@ -73,9 +72,9 @@ class BlockRepository implements BlockRepositoryInterface
73
72
private $ collectionProcessor ;
74
73
75
74
/**
76
- * @var WYSIWYGValidatorInterface
75
+ * @var HydratorInterface
77
76
*/
78
- private $ wysiwygValidator ;
77
+ private $ hydrator ;
79
78
80
79
/**
81
80
* @param ResourceBlock $resource
@@ -87,7 +86,7 @@ class BlockRepository implements BlockRepositoryInterface
87
86
* @param DataObjectProcessor $dataObjectProcessor
88
87
* @param StoreManagerInterface $storeManager
89
88
* @param CollectionProcessorInterface $collectionProcessor
90
- * @param WYSIWYGValidatorInterface |null $wysiwygValidator
89
+ * @param HydratorInterface |null $hydrator
91
90
*/
92
91
public function __construct (
93
92
ResourceBlock $ resource ,
@@ -99,7 +98,7 @@ public function __construct(
99
98
DataObjectProcessor $ dataObjectProcessor ,
100
99
StoreManagerInterface $ storeManager ,
101
100
CollectionProcessorInterface $ collectionProcessor = null ,
102
- ?WYSIWYGValidatorInterface $ wysiwygValidator = null
101
+ ?HydratorInterface $ hydrator = null
103
102
) {
104
103
$ this ->resource = $ resource ;
105
104
$ this ->blockFactory = $ blockFactory ;
@@ -110,46 +109,14 @@ public function __construct(
110
109
$ this ->dataObjectProcessor = $ dataObjectProcessor ;
111
110
$ this ->storeManager = $ storeManager ;
112
111
$ this ->collectionProcessor = $ collectionProcessor ?: $ this ->getCollectionProcessor ();
113
- $ this ->wysiwygValidator = $ wysiwygValidator
114
- ?? ObjectManager::getInstance ()->get (WYSIWYGValidatorInterface::class);
115
- }
116
-
117
- /**
118
- * Validate block's content.
119
- *
120
- * @param Data\BlockInterface|Block $block
121
- * @throws CouldNotSaveException
122
- * @return void
123
- */
124
- private function validateHtml (Data \BlockInterface $ block ): void
125
- {
126
- $ oldContent = null ;
127
- if ($ block ->getId ()) {
128
- if ($ block instanceof Block && $ block ->getOrigData ()) {
129
- $ oldContent = $ block ->getOrigData (Data \BlockInterface::CONTENT );
130
- } else {
131
- $ oldBlock = $ this ->getById ($ block ->getId ());
132
- $ oldContent = $ oldBlock ->getContent ();
133
- }
134
- }
135
- if ($ block ->getContent () && $ block ->getContent () !== $ oldContent ) {
136
- //Validate HTML content.
137
- try {
138
- $ this ->wysiwygValidator ->validate ($ block ->getContent ());
139
- } catch (ValidationException $ exception ) {
140
- throw new CouldNotSaveException (
141
- __ ('Content HTML has restricted elements. %1 ' , $ exception ->getMessage ()),
142
- $ exception
143
- );
144
- }
145
- }
112
+ $ this ->hydrator = $ hydrator ?? ObjectManager::getInstance ()->get (HydratorInterface::class);
146
113
}
147
114
148
115
/**
149
116
* Save Block data
150
117
*
151
118
* @param \Magento\Cms\Api\Data\BlockInterface $block
152
- * @return Block|Data\BlockInterface
119
+ * @return Block
153
120
* @throws CouldNotSaveException
154
121
*/
155
122
public function save (Data \BlockInterface $ block )
@@ -158,7 +125,9 @@ public function save(Data\BlockInterface $block)
158
125
$ block ->setStoreId ($ this ->storeManager ->getStore ()->getId ());
159
126
}
160
127
161
- $ this ->validateHtml ($ block );
128
+ if ($ block ->getId () && $ block instanceof Block && !$ block ->getOrigData ()) {
129
+ $ block = $ this ->hydrator ->hydrate ($ this ->getById ($ block ->getId ()), $ this ->hydrator ->extract ($ block ));
130
+ }
162
131
163
132
try {
164
133
$ this ->resource ->save ($ block );
0 commit comments