*
*
[eyebrow][headline][body]
* [btnA][btnB]
*
*
* @param array $attrs Block attributes.
* @param string $content Block content (unused; this module has no children).
* @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'] ?? 'off') === 'on';
$use_second_button = ($advanced['useSecondButton']['desktop']['value'] ?? 'off') === 'on';
$overlay_html = $use_overlay
? ''
: '';
$text_html = sprintf(
'%1$s%2$s%3$s
',
$elements->render(['attrName' => 'subtitle']),
$elements->render(['attrName' => 'title']),
$elements->render(['attrName' => 'description'])
);
// Buttons are left out of the markup entirely rather than hidden with
// CSS. A display:none anchor keeps its place in the tab order, so a
// keyboard user would land on a control nobody can see. ButtonElement
// returns an empty string when the label is blank, which is how an
// author switches the primary button off.
$buttons_html = ButtonElement::render($attrs['btnA'] ?? [], 'dtq-btn-default dtq-cta-box__btn--a');
if ($use_second_button) {
$buttons_html .= ButtonElement::render($attrs['btnB'] ?? [], 'dtq-btn-default dtq-cta-box__btn--b');
}
$actions_html = '' !== $buttons_html
? sprintf('%1$s
', $buttons_html)
: '';
$children = sprintf(
'%2$s%3$s%4$s
',
esc_attr(self::wrapper_class($advanced)),
$overlay_html,
$text_html,
$actions_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' => [
$elements->style_components(['attrName' => 'module']),
$children,
],
]
);
}
}