Skip to content

Commit

Permalink
KAD-3299 Button settings
Browse files Browse the repository at this point in the history
  • Loading branch information
oakesjosh committed Aug 28, 2024
1 parent 6bc4d5b commit 63f76ea
Show file tree
Hide file tree
Showing 4 changed files with 1,794 additions and 138 deletions.
58 changes: 57 additions & 1 deletion includes/blocks/class-kadence-blocks-search-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,63 @@ public function build_css( $attributes, $css, $unique_id, $unique_style_id ) {
* @return mixed
*/
public function build_html( $attributes, $unique_id, $content, $block_instance ) {
return 'Search Block';

$content .= $this->build_button( $attributes, $unique_id, $content );

return $content;
}

private function build_button( $attributes, $unique_id, $content ) {
$class_id = $unique_id;
$outer_classes = array( 'kadence-search-button', 'wp-block-kadence-search-button', 'wp-block-kadence-search-button' . $unique_id );
$wrapper_args = array(
'class' => implode( ' ', $outer_classes ),
'data-uniqueid' => $unique_id,
);
$wrapper_attributes = get_block_wrapper_attributes( $wrapper_args );
$classes = array( 'kb-button', 'kt-button', 'button', 'kb-search-button', 'kb-btn' . $class_id );
$classes[] = ! empty( $attributes['sizePreset'] ) ? 'kt-btn-size-' . $attributes['sizePreset'] : 'kt-btn-size-standard';
$classes[] = ! empty( $attributes['widthType'] ) ? 'kt-btn-width-type-' . $attributes['widthType'] : 'kt-btn-width-type-auto';
$classes[] = ! empty( $attributes['inheritStyles'] ) ? 'kb-btn-global-' . $attributes['inheritStyles'] : 'kb-btn-global-fill';
$classes[] = ! empty( $attributes['text'] ) ? 'kt-btn-has-text-true' : 'kt-btn-has-text-false';
$classes[] = ! empty( $attributes['icon'] ) ? 'kt-btn-has-svg-true' : 'kt-btn-has-svg-false';
if ( ! empty( $attributes['inheritStyles'] ) && 'inherit' === $attributes['inheritStyles'] ) {
$classes[] = 'wp-block-button__link';
}
$button_args = array(
'class' => implode( ' ', $classes ),
);
if ( ! empty( $attributes['anchor'] ) ) {
$button_args['id'] = $attributes['anchor'];
}
$button_args['type'] = 'submit';
if ( ! empty( $attributes['label'] ) ) {
$button_args['aria-label'] = $attributes['label'];
}
$button_wrap_attributes = array();
foreach ( $button_args as $key => $value ) {
$button_wrap_attributes[] = $key . '="' . esc_attr( $value ) . '"';
}
$button_wrapper_attributes = implode( ' ', $button_wrap_attributes );
$text = ! empty( $attributes['text'] ) ? '<span class="kt-btn-inner-text">' . $attributes['text'] . '</span>' : '';
$svg_icon = '';
if ( ! empty( $attributes['icon'] ) ) {
$type = substr( $attributes['icon'], 0, 2 );
$line_icon = ( ! empty( $type ) && 'fe' == $type ? true : false );
$fill = ( $line_icon ? 'none' : 'currentColor' );
$stroke_width = false;

if ( $line_icon ) {
$stroke_width = 2;
}
$svg_icon = Kadence_Blocks_Svg_Render::render( $attributes['icon'], $fill, $stroke_width );
}
$icon_left = ! empty( $svg_icon ) && ! empty( $attributes['iconSide'] ) && 'left' === $attributes['iconSide'] ? '<span class="kb-svg-icon-wrap kb-svg-icon-' . esc_attr( $attributes['icon'] ) . ' kt-btn-icon-side-left">' . $svg_icon . '</span>' : '';
$icon_right = ! empty( $svg_icon ) && ! empty( $attributes['iconSide'] ) && 'right' === $attributes['iconSide'] ? '<span class="kb-svg-icon-wrap kb-svg-icon-' . esc_attr( $attributes['icon'] ) . ' kt-btn-icon-side-right">' . $svg_icon . '</span>' : '';
$html_tag = 'button';
$content = sprintf( '<%1$s %2$s>%3$s%4$s%5$s</%1$s>', $html_tag, $button_wrapper_attributes, $icon_left, $text, $icon_right );
$content = sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $content );
return $content;
}

/**
Expand Down
Loading

0 comments on commit 63f76ea

Please sign in to comment.