false, 'selector' => $selector, 'declaration' => 'position: absolute; z-index: 999;', ]; $opp_side = 'left' === $side ? 'right' : 'left'; $out[] = [ 'atRules' => false, 'selector' => $selector, 'declaration' => $is_center_x ? sprintf('%1$s: 50%%; %2$s: auto;', $side, $opp_side) : sprintf('%1$s: %2$s; %3$s: auto;', $side, '' !== $offset_x ? $offset_x : '50%', $opp_side), ]; $opp_vert = 'top' === $vert ? 'bottom' : 'top'; $out[] = [ 'atRules' => false, 'selector' => $selector, 'declaration' => $is_center_y ? sprintf('%1$s: 50%%; %2$s: auto;', $vert, $opp_vert) : sprintf('%1$s: %2$s; %3$s: auto;', $vert, '' !== $offset_y ? $offset_y : '50%', $opp_vert), ]; $val_x = '0'; $val_y = '0'; if ($is_center_x) { $val_x = ('right_top' === $position || 'right_bottom' === $position) ? '50%' : '-50%'; } if ($is_center_y) { $val_y = ('right_top' === $position || 'left_top' === $position) ? '-50%' : '50%'; } $out[] = [ 'atRules' => false, 'selector' => $selector, 'declaration' => sprintf('transform: translateX(%1$s) translateY(%2$s);', $val_x, $val_y), ]; return $out; } /** * Build the custom IconBox declarations from the flat `module.advanced` attrs. * * Ports the D4 `render_css()` set_style calls into the custom-style array * shape: `['atRules' => false, 'selector' => ..., 'declaration' => ...]`. * * @param array $advanced The `module.advanced` attrs array. * @param string $order_class The module order class. * @return array */ public static function build_iconbox_styles($advanced, $order_class) { if (!is_array($advanced)) { return []; } $styles = []; $use_image = ($advanced['useImage']['desktop']['value'] ?? 'off') === 'on'; $placement = $advanced['iconPlacement']['desktop']['value'] ?? 'normal'; $alignment = $advanced['contentAlignment']['desktop']['value'] ?? 'center'; $icon_color = $advanced['iconColor']['desktop']['value'] ?? '#333'; $icon_bg = $advanced['iconBg']['desktop']['value'] ?? ''; $badge_bg = $advanced['badgeBg']['desktop']['value'] ?? ''; $icon_rotate = $advanced['iconBgRotate']['desktop']['value'] ?? '0deg'; $icon_width = $advanced['iconWidth']['desktop']['value'] ?? 'auto'; $icon_height = $advanced['iconHeight']['desktop']['value'] ?? 'auto'; $icon_size = $advanced['iconSize']['desktop']['value'] ?? '60px'; $icon_spacing = $advanced['iconSpacing']['desktop']['value'] ?? '10px'; $title_spacing = $advanced['titleSpacing']['desktop']['value'] ?? '10px'; $is_negative = '-' === substr((string) $icon_rotate, 0, 1); $rotate_deg = absint($icon_rotate); // Alignment. $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox', 'declaration' => sprintf('text-align: %1$s;', $alignment), ]; if ('right' === $alignment) { $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon-wrap', 'declaration' => 'justify-content: flex-end;', ]; } elseif ('center' === $alignment) { $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon-wrap', 'declaration' => 'justify-content: center;', ]; } // Icon spacing: bottom margin when stacked (normal), row gap when beside content (left/right). if ('normal' === $placement) { $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon-wrap', 'declaration' => sprintf('margin-bottom: %1$s;', $icon_spacing), ]; } elseif ('left' === $placement || 'right' === $placement) { $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox-inner', 'declaration' => sprintf('gap: %1$s;', $icon_spacing), ]; } // Icon box rotate. $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon', 'declaration' => sprintf('transform: rotate(%1$s);', $icon_rotate), ]; $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon i, ' . $order_class . ' .dtq-iconbox__icon img', 'declaration' => sprintf('transform: rotate(%1$s%2$sdeg);', $is_negative ? '' : '-', $rotate_deg), ]; // Icon width / height. if ('auto' !== $icon_width) { $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon', 'declaration' => sprintf('width: %1$s;', $icon_width), ]; } if ('auto' !== $icon_height) { $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon', 'declaration' => sprintf('height: %1$s;', $icon_height), ]; } // Icon background. if (!empty($icon_bg)) { $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon', 'declaration' => sprintf('background-color: %1$s;', $icon_bg), ]; } // Icon padding applies to both modes. It lands on .dtq-iconbox__icon, // which is inline-flex and so hugs its content — with a background and a // radius but no padding you get a shape tight to the glyph instead of a // chip, and an icon chip is the most common Icon Box design there is. // module.json puts no useImage condition on the control, so it reads as // universal; it used to be emitted in the image branch only. // Spacing fields read every stored shape (Shared\Spacing). No // default: unset sides keep the stylesheet's. $icon_pad_css = Spacing::css('padding', $advanced['iconPadding'] ?? null, 'desktop'); if ('' !== $icon_pad_css) { $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon', 'declaration' => $icon_pad_css, ]; } if (!$use_image) { // Icon font. $icon_attr = $advanced['icon']['desktop']['value'] ?? []; $icon_type = is_array($icon_attr) ? ($icon_attr['type'] ?? '') : ''; $font_family = 'fa' === $icon_type ? 'FontAwesome' : 'ETmodules'; $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon i', 'declaration' => sprintf('font-family: "%1$s"; font-size: %2$s; color: %3$s;', $font_family, $icon_size, $icon_color), ]; } else { // Image icon. $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__icon img', 'declaration' => sprintf('width: %1$s;', $icon_size), ]; } // Badge background. if (!empty($badge_bg)) { $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__badge', 'declaration' => sprintf('background-color: %1$s;', $badge_bg), ]; } // Title bottom spacing. $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__title', 'declaration' => sprintf('padding-bottom: %1$s;', $title_spacing), ]; // Absolute icon placement (only when iconPlacement === 'absolute'). if ('absolute' === $placement) { foreach (self::build_absolute_styles($advanced, 'icon', $order_class . ' .dtq-iconbox__icon') as $s) { $styles[] = $s; } } // Badge placement (badge is always absolutely positioned) + padding. foreach (self::build_absolute_styles($advanced, 'badge', $order_class . ' .dtq-iconbox__badge') as $s) { $styles[] = $s; } // Unset sides come from the default, which Divi also merges into the // attrs before this runs. $styles[] = [ 'atRules' => false, 'selector' => $order_class . ' .dtq-iconbox__badge', 'declaration' => Spacing::css('padding', $advanced['badgePadding'] ?? null, 'desktop', '5px|15px|5px|15px'), ]; // --------------------------------------------------------------- // Additive responsive (tablet/phone) output. Desktop entries above // are untouched; the loop below only APPENDS @media entries for // responsive fields whose breakpoint value exists and differs from // the next-larger breakpoint. // --------------------------------------------------------------- $breakpoints = [ 'tablet' => '@media only screen and (max-width: 980px)', 'phone' => '@media only screen and (max-width: 767px)', ]; foreach ($breakpoints as $breakpoint => $at_rule) { $larger = 'phone' === $breakpoint ? 'tablet' : 'desktop'; // Resolve a field's value at this breakpoint, only when it exists // and differs from the next-larger breakpoint's resolved value. $bp = function ($key) use ($advanced, $breakpoint, $larger) { $val = $advanced[$key][$breakpoint]['value'] ?? null; if (null === $val) { return null; } $larger_val = $advanced[$key][$larger]['value'] ?? ($advanced[$key]['desktop']['value'] ?? null); if ($val === $larger_val) { return null; } return $val; }; // Icon spacing (normal → margin-bottom, left/right → gap) — iconSpacing. if ('normal' === $placement) { $val = $bp('iconSpacing'); if (null !== $val) { $styles[] = [ 'atRules' => $at_rule, 'selector' => $order_class . ' .dtq-iconbox__icon-wrap', 'declaration' => sprintf('margin-bottom: %1$s;', $val), ]; } } elseif ('left' === $placement || 'right' === $placement) { $val = $bp('iconSpacing'); if (null !== $val) { $styles[] = [ 'atRules' => $at_rule, 'selector' => $order_class . ' .dtq-iconbox-inner', 'declaration' => sprintf('gap: %1$s;', $val), ]; } } // Icon width — iconWidth (skip when desktop resolved to auto-only // is irrelevant; emit whenever a non-auto responsive value exists). $val = $bp('iconWidth'); if (null !== $val && 'auto' !== $val) { $styles[] = [ 'atRules' => $at_rule, 'selector' => $order_class . ' .dtq-iconbox__icon', 'declaration' => sprintf('width: %1$s;', $val), ]; } // Icon height — iconHeight. $val = $bp('iconHeight'); if (null !== $val && 'auto' !== $val) { $styles[] = [ 'atRules' => $at_rule, 'selector' => $order_class . ' .dtq-iconbox__icon', 'declaration' => sprintf('height: %1$s;', $val), ]; } // Icon padding — iconPadding. Both modes, same as the static block. $val = $bp('iconPadding'); if (null !== $val) { $pad_css = Spacing::css('padding', $advanced['iconPadding'] ?? null, $breakpoint); if ('' !== $pad_css) { $styles[] = [ 'atRules' => $at_rule, 'selector' => $order_class . ' .dtq-iconbox__icon', 'declaration' => $pad_css, ]; } } if (!$use_image) { // Icon font size — iconSize (font icon branch). $val = $bp('iconSize'); if (null !== $val) { $styles[] = [ 'atRules' => $at_rule, 'selector' => $order_class . ' .dtq-iconbox__icon i', 'declaration' => sprintf('font-size: %1$s;', $val), ]; } } else { // Image icon size — iconSize (image width branch). $val = $bp('iconSize'); if (null !== $val) { $styles[] = [ 'atRules' => $at_rule, 'selector' => $order_class . ' .dtq-iconbox__icon img', 'declaration' => sprintf('width: %1$s;', $val), ]; } } // Title bottom spacing — titleSpacing. $val = $bp('titleSpacing'); if (null !== $val) { $styles[] = [ 'atRules' => $at_rule, 'selector' => $order_class . ' .dtq-iconbox__title', 'declaration' => sprintf('padding-bottom: %1$s;', $val), ]; } } return $styles; } /** * Generate the module styles. * * @param array $args Style args. * @return void */ public static function module_styles($args) { $attrs = $args['attrs'] ?? []; $elements = $args['elements']; $settings = $args['settings'] ?? []; $order_class = $args['orderClass'] ?? ''; $advanced = $attrs['module']['advanced'] ?? []; $custom_styles = self::build_iconbox_styles($advanced, $order_class); $all_styles = [ // Module wrapper styles (background, spacing, etc.). $elements->style( [ 'attrName' => 'module', 'styleProps' => [ 'disabledOn' => [ 'disabledModuleVisibility' => $settings['disabledModuleVisibility'] ?? null, ], ], ] ), // Title font / heading styles. $elements->style(['attrName' => 'title']), // Description font styles. $elements->style(['attrName' => 'description']), // Badge font + border styles. $elements->style(['attrName' => 'badge']), // Icon border + box-shadow styles. $elements->style(['attrName' => 'icon']), ]; if (!empty($custom_styles)) { $all_styles[] = $custom_styles; } // Custom CSS (Advanced tab). $all_styles[] = CssStyle::style( [ 'selector' => $order_class, 'attr' => $attrs['css'] ?? [], 'cssFields' => self::custom_css_fields(), ] ); Style::add( [ 'id' => $args['id'], 'name' => $args['name'], 'orderIndex' => $args['orderIndex'], 'storeInstance' => $args['storeInstance'], 'styles' => $all_styles, ] ); } }