Skip to content

Commit a0787b3

Browse files
committed
Add gradient overlay support
1 parent f106632 commit a0787b3

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "totalonion"
77
}
88
],
9-
"version": "1.0.4",
9+
"version": "1.1.0",
1010
"require": {},
1111
"minimum-stability": "dev"
1212
}

get-pattern.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Get Pattern
44
* Description: Child Block Creator
55
* Author: Total Onion
6-
* Version: 1.0.4
6+
* Version: 1.1.0
77
*/
88

99
if (!defined('ABSPATH')) {

inc/transforms/Fields.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)