* [figure | icon] [content (title, desc, button)] * * * @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_icon = ($advanced['useIcon']['desktop']['value'] ?? 'off') === 'on'; $use_badge = ($advanced['useBadge']['desktop']['value'] ?? 'off') === 'on'; $use_button = ($advanced['useButton']['desktop']['value'] ?? 'off') === 'on'; $overlay_on = ($advanced['overlayOnHover']['desktop']['value'] ?? 'on') === 'on'; $hover_anim = $advanced['imageHoverAnimation']['desktop']['value'] ?? 'none'; $use_light = ($advanced['useLightbox']['desktop']['value'] ?? 'off') === 'on'; // The D5 upload field stores the image as an object (`{ src, ... }`); // accept both that and a plain URL string. $photo_val = $attrs['photo']['innerContent']['desktop']['value'] ?? ''; $photo_src = is_array($photo_val) ? ($photo_val['src'] ?? '') : $photo_val; $photo_alt = $attrs['photo']['advanced']['alt']['desktop']['value'] ?? ''; // Badge. $badge_html = ''; if ($use_badge) { $badge_html = $elements->render(['attrName' => 'badge']); } // Figure (only when icon is OFF and an image is set). $figure_html = ''; if (!$use_icon && !empty($photo_src)) { $overlay_html = ''; if ($overlay_on) { $overlay_icon = $advanced['overlayIcon']['desktop']['value'] ?? ''; if (is_array($overlay_icon)) { $overlay_uni = $overlay_icon['unicode'] ?? ''; $overlay_type = $overlay_icon['type'] ?? 'divi'; $overlay_wt = $overlay_icon['weight'] ?? '400'; } else { $overlay_parts = explode('||', (string) $overlay_icon); $overlay_uni = $overlay_parts[0] ?? ''; $overlay_type = $overlay_parts[1] ?? 'divi'; $overlay_wt = $overlay_parts[2] ?? '400'; } if ('' !== $overlay_uni) { $overlay_font = 'fa' === $overlay_type ? 'FontAwesome' : 'ETmodules'; dtq_inject_fa_icons($overlay_uni . '||' . $overlay_type . '||' . $overlay_wt); $overlay_html = sprintf( '
%3$s
', esc_attr($overlay_font), esc_attr($overlay_wt), dtq_resolve_icon_unicode($overlay_uni) ); } } $lightbox_class = $use_light ? ' dtq-lightbox' : ''; $figure_html = sprintf( '
%1$s%2$s%4$s
', $badge_html, $overlay_html, esc_url($photo_src), esc_attr($photo_alt), esc_attr($lightbox_class) ); } // Icon (only when icon is ON). $icon_html = ''; if ($use_icon) { $icon_value = $advanced['icon']['desktop']['value'] ?? ''; if (is_array($icon_value)) { $icon_uni = $icon_value['unicode'] ?? ''; $icon_type = $icon_value['type'] ?? 'divi'; $icon_wt = $icon_value['weight'] ?? '400'; } else { $icon_parts = explode('||', (string) $icon_value); $icon_uni = $icon_parts[0] ?? ''; $icon_type = $icon_parts[1] ?? 'divi'; $icon_wt = $icon_parts[2] ?? '400'; } $icon_font = 'fa' === $icon_type ? 'FontAwesome' : 'ETmodules'; dtq_inject_fa_icons($icon_uni . '||' . $icon_type . '||' . $icon_wt); $icon_html = sprintf( '
%1$s
%4$s
', $badge_html, esc_attr($icon_font), esc_attr($icon_wt), dtq_resolve_icon_unicode($icon_uni) ); } // Content (title, description, button). $title_html = $elements->render(['attrName' => 'title']); $desc_html = $elements->render(['attrName' => 'description']); $button_html = ''; if ($use_button) { $button_html = sprintf( '
%1$s
', ButtonElement::render($attrs['button'] ?? [], 'dtq-btn-default dtq-btn-card') ); } $content_html = sprintf( '
%1$s%2$s%3$s
', $title_html, $desc_html, $button_html ); $card_classes = sprintf( 'dtq-card dtq-swapped-img-selector dtq-hover--%1$s use-icon-%2$s', esc_attr($hover_anim), $use_icon ? 'on' : 'off' ); $children = sprintf( '
%2$s%3$s%4$s
', esc_attr($card_classes), $figure_html, $icon_html, $content_html ); 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, ], ] ); } }