@@ -13,6 +13,7 @@ public static function transform(string $html, string $type = 'fields', string $
1313 $ html = self ::replacePostMeta ($ html , $ type );
1414 $ html = self ::replaceGenerics ($ html , $ type );
1515 $ html = self ::replaceNodeValues ($ html , $ type , $ name );
16+ $ html = self ::wrapGradientOverlay ($ html );
1617 return $ html ;
1718 }
1819 // Repeaters
@@ -167,6 +168,35 @@ private static function replaceNodeValues(string $html, string $type, string $na
167168 $ node ->nodeValue = "{{ {$ postInfo }. {$ elem } }} " ;
168169 }
169170 }
171+ return Utils::saveDom ($ dom );
172+ }
173+ // Gradient Overlay
174+ private static function wrapGradientOverlay (string $ html ): string
175+ {
176+ $ dom = Utils::loadDom ($ html );
177+ $ xpath = new \DOMXPath ($ dom );
178+ $ nodes = $ xpath ->query ('//*[@data-pattern-gradient-overlay] ' );
179+
180+ foreach ($ nodes as $ node ) {
181+ if ($ node ->getAttribute ('data-renderdynamic ' ) !== '1 ' ) {
182+ continue ;
183+ }
184+
185+ $ container = $ node ->parentNode ;
186+
187+ $ start = $ dom ->createDocumentFragment ();
188+ $ start ->appendXML ('<inserttwig>{% if fields.enable_gradient_overlay %}</inserttwig> ' );
189+
190+ $ end = $ dom ->createDocumentFragment ();
191+ $ end ->appendXML ('<inserttwig>{% endif %}</inserttwig> ' );
192+
193+ $ container ->parentNode ->insertBefore ($ start , $ container );
194+ if ($ container ->nextSibling ) {
195+ $ container ->parentNode ->insertBefore ($ end , $ container ->nextSibling );
196+ } else {
197+ $ container ->parentNode ->appendChild ($ end );
198+ }
199+ }
170200
171201 return Utils::saveDom ($ dom );
172202 }
0 commit comments