Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Table Block Markup #23

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions inc/blocks/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ function get_block_wrapper_attributes( array $attributes = [] ): string {

$normalized_attributes = [];
foreach ( $attributes as $key => $value ) {

// Skip empty values.
if ( empty( $value ) ) {
continue;
}

$normalized_attributes[] = $key . '="' . esc_attr( $value ) . '"';
}

Expand Down
13 changes: 9 additions & 4 deletions src/editor/blocks/table/children/column/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Travelopia\Blocks\Table\Column;

use WP_Block;

use function Travelopia\Blocks\Helpers\get_block_wrapper_attributes;
use function Travelopia\Blocks\Helpers\get_css_classes;
use function Travelopia\Blocks\Helpers\get_css_styles;
Expand All @@ -30,12 +32,13 @@ function bootstrap(): void {
/**
* Render this block.
*
* @param mixed[] $attributes The block attributes.
* @param string $content The block default content.
* @param mixed[] $attributes The block attributes.
* @param string $content The block default content.
* @param WP_Block $block The block object.
*
* @return string
*/
function render( array $attributes = [], string $content = '' ): string {
function render( array $attributes = [], string $content = '', WP_Block $block = null ): string {
$border_styles = get_border_styles( $attributes );

// Get block attributes.
Expand All @@ -56,7 +59,9 @@ function render( array $attributes = [], string $content = '' ): string {
);

$html_tag = 'td';
if ( ! empty( $attributes['type'] ) ) {
if ( ! empty( $block->context['travelopia/table-row-container-type'] )
&& 'tbody' !== $block->context['travelopia/table-row-container-type']
) {
$html_tag = 'th';
}

Expand Down