File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,14 +40,23 @@ public function beforeSave(
4040 && ($ identifier = $ block ->getIdentifier ())
4141 && ($ content = $ block ->getContent ())
4242 ) {
43- $ block ->setContent (
44- substr_replace (
45- $ content ,
46- ' data- ' . $ this ->moduleConfig ->getBlockIdentifierDataAttributeName () . '=" ' . $ identifier . '" ' ,
47- strpos ($ content , '<div ' ) + 4 ,
48- 0
49- )
50- );
43+ $ firstWord = strtok ($ content , ' ' );
44+
45+ // if tags are removed from the first "word" and the values are not equal then we have HTML to edit
46+ if (strip_tags ($ firstWord ) !== $ firstWord ) {
47+ $ tag = explode ('> ' , explode ('< ' , $ content )[1 ])[0 ]; // parsing HTML with PHP is gross
48+
49+ $ block ->setContent (
50+ substr_replace (
51+ $ content ,
52+ ' data- ' . $ this ->moduleConfig ->getBlockIdentifierDataAttributeName () . '=" ' . $ identifier . '" ' ,
53+ strpos ($ content , $ tag ) + strlen ($ tag ),
54+ 0
55+ )
56+ );
57+ } else {
58+ $ block ->setContent ('<!-- CMS identifier = ' . $ identifier . ' --> ' . "\n" . $ content );
59+ }
5160 }
5261
5362 return [$ block ];
You can’t perform that action at this time.
0 commit comments