*
* The per-instance order number comes from the block orderIndex — the
* same number that forms the order class (.dtq_video_modal_{n}) — so the
* trigger's data-order matches the body.dtq-video-popup-{n} popup
* selectors that ModuleStylesTrait emits (the popup DOM is appended to
* , outside the module wrapper; the front-end magnific callbacks
* toggle that body class per module, exactly like D4).
*
* @param array $attrs Block attributes.
* @param string $content Block content (unused).
* @param WP_Block $block Parsed block.
* @param ModuleElements $elements Module elements helper.
*
* @return string
*/
public static function render_callback($attrs, $content, $block, $elements)
{
$advanced = $attrs['module']['advanced'] ?? [];
$use_overlay = $advanced['useOverlay']['desktop']['value'] ?? 'on';
$trigger_element = $advanced['triggerElement']['desktop']['value'] ?? 'icon';
$icon = $advanced['icon']['desktop']['value'] ?? '1';
$type = $advanced['type']['desktop']['value'] ?? 'yt';
$video_link = DynamicValue::resolve($advanced['videoLink']['desktop']['value'] ?? '');
$video = self::upload_src($advanced['video']['desktop']['value'] ?? '');
$custom_icon = self::upload_src($advanced['customPlayIcon']['desktop']['value'] ?? '');
$image_src = self::upload_src(DynamicValue::resolve($attrs['image']['innerContent']['desktop']['value'] ?? ''));
$image_alt = $attrs['image']['advanced']['alt']['desktop']['value'] ?? '';
// Per-instance order number (matches the order class suffix).
$order_number = $block->parsed_block['orderIndex'] ?? 0;
// Magnific popup is always needed on the front end (both source
// paths) — the library handles are registered in includes/assets.php.
if (function_exists('wp_enqueue_script')) {
wp_enqueue_script('divi-torque-lite-magnific-popup');
wp_enqueue_style('divi-torque-lite-magnific-popup');
}
// Trigger inner parts (mirrors D4 render_trigger()).
$icon_span = '';
if ('text' !== $trigger_element) {
$icons = self::play_icons();
$icon_html = 'custom' === $icon
? sprintf('', esc_url($custom_icon))
: ($icons[$icon] ?? $icons['1']);
$icon_span = sprintf('%1$s', $icon_html);
}
$text_span = '';
if ('icon' !== $trigger_element) {
$text_span = $elements->render(['attrName' => 'text']);
}
// Self-hosted inline modal (type=video only). Hidden via mfp-hide;
// magnific clones it into the popup on the front end.
$inline_modal = '';
$data_modal = '';
if ('video' === $type) {
$inline_modal = sprintf(
'
',
esc_url($image_src),
esc_attr($image_alt)
);
}
// Mirrors D4: youtu.be short links are rewritten to the full URL so
// the magnific youtube pattern matches.
if (false !== strpos($video_link, 'youtu.be')) {
$video_link = str_replace('youtu.be/', 'youtube.com/watch?v=', $video_link);
}
// The trigger must not be a navigating link: the video URL lives in
// data-video-url and frontend.js preventDefaults the click, so the
// browser can never follow it to YouTube/Vimeo if the popup script
// hasn't bound yet (deferred/optimized JS, load races).
$children = sprintf(
'