start_controls_section( 'tablekit_table_section', array( 'label' => __( 'Table', 'table-builder-block' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ) ); $this->add_control( 'table_id', array( 'label' => __( 'Select Table', 'table-builder-block' ), 'type' => \Elementor\Controls_Manager::SELECT2, 'options' => $this->get_table_options(), 'default' => '', 'render_type' => 'template', 'label_block' => true, 'description' => __( 'Create and manage tables under TableKit → Tables in the WP admin.', 'table-builder-block' ), ) ); $this->add_control( 'block_index', array( 'label' => __( 'Select Block', 'table-builder-block' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => array( '' => __( '— All Blocks —', 'table-builder-block' ) ), 'default' => self::ALL_BLOCKS, 'render_type' => 'template', 'label_block' => true, 'description' => __( 'Choose a specific block to display. Or select — All Blocks — to show all blocks.', 'table-builder-block' ), ) ); $this->end_controls_section(); } // ------------------------------------------------------------------------- // Rendering // ------------------------------------------------------------------------- /** * Renders the widget on the frontend/editor: resolves the selected table post, * optionally narrow to one block, print shared/per-table CSS, render the * table block(s), and print their view scripts. * * @return void */ protected function render(): void { $settings = $this->get_settings_for_display(); $raw_id = $settings['table_id'] ?? 0; if ( is_array( $raw_id ) ) { $raw_id = reset( $raw_id ); } $table_id = absint( $raw_id ); if ( empty( $table_id ) ) { $this->render_placeholder( __( 'Select a table to display.', 'table-builder-block' ) ); return; } $post = get_post( $table_id ); if ( ! $post ) { $this->render_placeholder( __( 'Table not found.', 'table-builder-block' ) ); return; } if ( class_exists( '\\TableBuilder\\Config\\Blocks' ) ) { \TableBuilder\Config\Blocks::instance()->enqueue_block_assets(); } $all_blocks = parse_blocks( $post->post_content ); $table_blocks = $this->filter_table_blocks( $all_blocks ); $block_index = $settings['block_index'] ?? self::ALL_BLOCKS; $blocks_to_render = $all_blocks; if ( self::ALL_BLOCKS !== $block_index && '' !== $block_index ) { $index = (int) $block_index; if ( isset( $table_blocks[ $index ] ) ) { $blocks_to_render = array( $table_blocks[ $index ] ); } } $block_names = $this->collect_block_names( $blocks_to_render ); $this->print_shared_styles( $block_names ); $this->print_table_styles( $table_id, $post->post_content ); echo '
'; foreach ( $blocks_to_render as $block ) { echo ( new WP_Block( $block ) )->render(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- standard core block-rendering output, same as render_block(). } echo '
'; $this->print_block_scripts( $block_names ); if ( class_exists( '\\TableBuilder\\Shortcode\\ShortcodeUtils' ) ) { echo \TableBuilder\Shortcode\ShortcodeUtils::get_elementor_init_script(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static hardcoded