Automattic\WooCommerce\Blocks\BlockTypes
FeaturedItem::render
Render the featured item block.
Метод класса: FeaturedItem{}
Хуков нет.
Возвращает
Строку. Rendered block type output.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->render( $attributes, $content, $block );
- $attributes(массив) (обязательный)
- Block attributes.
- $content(строка) (обязательный)
- Block content.
- $block(WP_Block) (обязательный)
- Block instance.
Код FeaturedItem::render() FeaturedItem::render WC 10.7.0
protected function render( $attributes, $content, $block ) {
$item = $this->get_item( $attributes );
if ( ! $item ) {
return '';
}
$aria_label = $attributes['ariaLabel'] ?? '';
$attributes = wp_parse_args( $attributes, $this->defaults );
$attributes['height'] = $attributes['height'] ?? wc_get_theme_support( 'featured_block::default_height', 500 );
$image_url = esc_url( $this->get_image_url( $attributes, $item ) );
$styles = $this->get_styles( $attributes );
$classes = $this->get_classes( $attributes );
$output = sprintf( '<div class="%1$s wp-block-woocommerce-%2$s" style="%3$s">', esc_attr( trim( $classes ) ), $this->block_name, esc_attr( $styles ) );
$output .= sprintf( '<div class="wc-block-%s__wrapper">', $this->block_name );
$output .= $this->render_overlay( $attributes );
if ( ! $attributes['isRepeated'] && ! $attributes['hasParallax'] ) {
$output .= $this->render_image( $attributes, $item, $image_url );
} else {
$output .= $this->render_bg_image( $attributes, $image_url );
}
if ( isset( $aria_label ) && ! empty( $aria_label ) ) {
$p = new \WP_HTML_Tag_Processor( $content );
if ( $p->next_tag( 'a', [ 'class' => 'wp-block-button__link' ] ) ) {
$p->set_attribute( 'aria-label', $aria_label );
$content = $p->get_updated_html();
}
}
// Render additional attributes (e.g. description/price) for legacy compatibility.
$output .= $this->render_attributes( $item, $attributes );
if ( ! empty( $content ) ) {
$output .= sprintf( '<div class="wc-block-%s__inner-blocks">%s</div>', $this->block_name, $content );
}
$output .= '</div>';
$output .= '</div>';
return $output;
}