'', '2' => ' ', '3' => '', '4' => ' ', '5' => '', '6' => '', ]; } /** * Normalize a D5 upload field value: migrated D4 values are plain URL * strings, native D5 values may be objects ({ src, ... }). * * @param mixed $val Upload field value. * * @return string */ public static function upload_src($val) { if (is_array($val)) { return $val['src'] ?? ''; } return (string) $val; } /** * Server-side render for the Video Modal module. * * Mirrors the D4 markup (and the VB edit component) exactly: *
* [inline modal (self-hosted only, mfp-hide)] *
* * [icon span][text span] * *
* [overlay figure] *
* * 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('custom-icon', 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_attr($order_number), esc_url($video) ); $data_modal = sprintf(' data-mfp-src="#dtq-video-popup-%1$s"', esc_attr($order_number)); } // Overlay image figure (mirrors D4: rendered whenever use_overlay is on). $img_overlay = ''; if ('on' === $use_overlay) { $img_overlay = sprintf( '
%2$s
', 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( '
%1$s
%6$s%7$s
%8$s
', $inline_modal, esc_attr($type), esc_attr($order_number), esc_url($video_link), $data_modal, $icon_span, $text_span, $img_overlay ); return Module::render( [ 'attrs' => $attrs, 'elements' => $elements, 'id' => $block->parsed_block['id'], 'name' => $block->block_type->name, 'moduleCategory' => $block->block_type->category, 'classnamesFunction' => [self::class, 'module_classnames'], 'stylesComponent' => [self::class, 'module_styles'], 'scriptDataComponent' => [self::class, 'module_script_data'], 'orderIndex' => $block->parsed_block['orderIndex'] ?? 0, 'storeInstance' => $block->parsed_block['storeInstance'] ?? null, 'children' => [ // Background pattern/mask and the box-shadow overlay are DOM, // not CSS. Without this call Divi renders them in the builder // and nowhere else, so the options silently do nothing on the // front end. $elements->style_components(['attrName' => 'module']), $children, ], ] ); } }