Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format
on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). Each changelog entry gets prefixed with the category of the
item (Added, Changed, Depreciated, Removed, Fixed, Security).

## [2026.03]

- Refactor Horizontal Tabs block into a dynamic block. Add reordering functionality.

## [2026.02]
- Added: `moderntribe/tribe_embed` composer package v1.1.0.
- Updated: Renamed "Moose" to "ModernPress" across the project (excluding Lando configs and deployment pipelines).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php declare(strict_types=1);

namespace Tribe\Plugin\Components\Blocks;

use Tribe\Plugin\Components\Abstracts\Abstract_Block_Controller;

/**
* Controller for the Horizontal Tabs block.
* Builds tab data from the block's inner blocks (saved order).
*/
class Horizontal_Tabs_Block_Controller extends Abstract_Block_Controller {

/**
* Tab items built from inner blocks (id, buttonId, label).
*
* @var array<int, array{id: string, buttonId: string, label: string}>
*/
protected array $tabs = [];

protected \WP_Block $block;

public function __construct( array $args = [] ) {
parent::__construct( $args );

$this->block = $args['block'] ?? new \WP_Block( [ 'blockName' => 'tribe/horizontal-tabs' ] );
$this->tabs = $this->build_tabs_from_inner_blocks();
}

/**
* @return array<int, array{id: string, buttonId: string, label: string}>
*/
public function get_tabs(): array {
return $this->tabs;
}

/**
* Whether the given tab (by index) should be selected. First tab is always active on the front-end.
*/
public function is_tab_selected( int $index ): bool {
return $index === 0;
}

/**
* Build tab list from parsed inner blocks (preserves saved order).
*
* @return array<int, array{id: string, buttonId: string, label: string}>
*/
protected function build_tabs_from_inner_blocks(): array {
$block = $this->block->parsed_block;
$inner_blocks = $block['innerBlocks'] ?? [];
$tabs = [];

foreach ( $inner_blocks as $inner ) {
if ( ( $inner['blockName'] ?? '' ) !== 'tribe/horizontal-tab' ) {
continue;
}

$attrs = $inner['attrs'] ?? [];
$id = $attrs['blockId'] ?? '';
$label = $attrs['tabLabel'] ?? '';
$tabs[] = [
'id' => $id,
'buttonId' => 'button-' . $id,
'label' => $label !== '' ? $label : __( 'Tab Label', 'tribe' ),
];
}

return $tabs;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"viewScript": "file:./view.js"
"viewScript": "file:./view.js",
"render": "file:./render.php"
}
Loading
Loading