in_array('linkTarget', $tokens, true), 'nofollow' => in_array('linkRel', $tokens, true), ]; } // Divi 4 positional on/off flags, only from a string. if (is_string($value)) { return [ 'new_window' => 'on' === strtolower($tokens[0] ?? ''), 'nofollow' => 'on' === strtolower($tokens[1] ?? ''), ]; } return ['new_window' => false, 'nofollow' => false]; } /** * Server-side render for the GradientHeading module. * * Mirrors the D4 markup: * [optional ]Title[/a] * * @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) { // Printed below, so resolve a dynamic-content binding first (#86). $title_value = DynamicValue::resolve($attrs['title']['innerContent']['desktop']['value'] ?? ''); $tag = $attrs['title']['decoration']['font']['font']['desktop']['value']['headingLevel'] ?? ''; if (empty($tag)) { $tag = $attrs['module']['advanced']['htmlTag']['desktop']['value'] ?? 'h1'; } $allowed_tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']; if (!in_array($tag, $allowed_tags, true)) { $tag = 'h1'; } $use_link = ($attrs['module']['advanced']['useLink']['desktop']['value'] ?? 'off') === 'on'; $link_url = DynamicValue::resolve($attrs['module']['advanced']['linkUrl']['desktop']['value'] ?? ''); $link_options = self::link_options($attrs['module']['advanced']['linkOptions']['desktop']['value'] ?? []); $link_target_new = $link_options['new_window']; $link_nofollow = $link_options['nofollow']; $inner_html = $title_value; if ($use_link && !empty($link_url)) { $inner_html = sprintf( '%4$s', esc_url($link_url), $link_target_new ? '_blank' : '_self', $link_nofollow ? ' rel="nofollow"' : '', $title_value ); } $children = sprintf( '<%1$s class="dtq-gradient-heading">%2$s', esc_attr($tag), $inner_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, ], ] ); } }