*
…
* * image:
*
*
* * @param string $side 'front' or 'back'. * @param array $attrs Block attributes. * @return string */ public static function render_media($side, $attrs) { $advanced = $attrs['module']['advanced'] ?? []; $media_type = $advanced[('front' === $side ? 'frontMediaType' : 'backMediaType')]['desktop']['value'] ?? 'icon'; if ('none' === $media_type) { return ''; } if ('icon' === $media_type) { $icon_value = $advanced[('front' === $side ? 'frontIcon' : 'backIcon')]['desktop']['value'] ?? ''; // The D5 icon picker stores an object; accept the legacy D4 // "unicode||type||weight" string too (pre-expansion values). if (is_array($icon_value)) { $uni = $icon_value['unicode'] ?? ''; $type = $icon_value['type'] ?? 'divi'; $wt = $icon_value['weight'] ?? '400'; } else { $parts = explode('||', (string) $icon_value); $uni = $parts[0] ?? ''; $type = $parts[1] ?? 'divi'; $wt = $parts[2] ?? '400'; } if ('' === $uni) { return ''; } $font = 'fa' === $type ? 'FontAwesome' : 'ETmodules'; dtq_inject_fa_icons($uni . '||' . $type . '||' . $wt); return sprintf( '
%4$s
', esc_attr($side), esc_attr($font), esc_attr($wt), dtq_resolve_icon_unicode($uni) ); } if ('image' === $media_type) { $image_attr = 'front' === $side ? ($attrs['frontImage'] ?? []) : ($attrs['backImage'] ?? []); $image_val = $image_attr['innerContent']['desktop']['value'] ?? ''; $image_src = is_array($image_val) ? ($image_val['src'] ?? '') : $image_val; $image_alt = $image_attr['advanced']['alt']['desktop']['value'] ?? ''; if (empty($image_src)) { return ''; } return sprintf( '
%3$s
', esc_attr($side), esc_url($image_src), esc_attr($image_alt) ); } return ''; } /** * Server-side render for the FlipBox module. * * Mirrors the D4 markup (and the VB edit component) exactly: *
*
*
*
*
*
* [figure] *
[title][subtitle][desc]
*
*
*
*
* ... back side (+ optional button wrap) ... *
*
*
*
*
* * The flip itself is pure CSS (module.scss) keyed off the same * wrapper/animation classes D4 used — no frontend JS. * * @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_button = ($advanced['useButton']['desktop']['value'] ?? 'off') === 'on'; $classes = self::build_animation_classes($advanced); $front_media = self::render_media('front', $attrs); $back_media = self::render_media('back', $attrs); $front_title = $elements->render(['attrName' => 'frontTitle']); $front_subtitle = $elements->render(['attrName' => 'frontSubtitle']); $front_desc = $elements->render(['attrName' => 'frontDescription']); $back_title = $elements->render(['attrName' => 'backTitle']); $back_subtitle = $elements->render(['attrName' => 'backSubtitle']); $back_desc = $elements->render(['attrName' => 'backDescription']); $button_html = ''; if ($use_button) { $button_html = sprintf( '
%1$s
', ButtonElement::render($attrs['button'] ?? [], 'dtq-flipbox-btn') ); } $front_card = sprintf( '
%1$s
%2$s%3$s%4$s
', $front_media, $front_title, $front_subtitle, $front_desc ); $back_card = sprintf( '
%1$s
%2$s%3$s%4$s%5$s
', $back_media, $back_title, $back_subtitle, $back_desc, $button_html ); // tabindex makes the card focusable so the flip can be triggered by // keyboard: the animation is CSS-driven off :hover, and module.scss now // pairs every one of those rules with :focus-within. Without a focusable // element the back side was unreachable without a mouse. $children = sprintf( '
%2$s%3$s
', esc_attr(implode(' ', $classes)), $front_card, $back_card ); 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, ], ] ); } }