PluginProbe
Tableberg – Simple Gutenberg Table Block / 0.0.2
Tableberg – Simple Gutenberg Table Block v0.0.2
1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 0.5.8 All 41 releases
tableberg / includes / Blocks / Row.php

Row.php in Tableberg – Simple Gutenberg Table Block 0.0.2, at includes/Blocks/Row.php

57 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Row Block
4 *
5 * @package Tableberg
6 */
7
8 namespace Tableberg\Blocks;
9
10 /**
11 * Handle the block registration on server side and rendering.
12 */
13 class Row {
14
15 /**
16 * Constructor
17 *
18 * @return void
19 */
20 public function __construct() {
21 add_action( 'init', array( $this, 'block_registration' ) );
22 }
23
24 /**
25 * Renders the custom row block on the server.
26 *
27 * @param array $attributes The block attributes.
28 * @param string $content The block content.
29 * @param WP_Block $block The block object.
30 * @return string Returns the HTML content for the custom row block.
31 */
32 public function render_tableberg_row_block( $attributes, $content, $block ) {
33 $footer_class = $attributes['isHeader'] ? 'tableberg-footer' : '';
34 $header_class = $attributes['isFooter'] ? 'tableberg-header' : '';
35
36 $classes = array( 'wp-block-tableberg-row', 'tableberg-row', $footer_class, $header_class );
37
38 $content = str_replace( '<tr class="wp-block-tableberg-row', '<tr class="' . join( ' ', $classes ) . '', $content );
39
40 return $content;
41 }
42
43 /**
44 * Register the block.
45 */
46 public function block_registration() {
47 $defaults = new \Tableberg\Defaults();
48 register_block_type(
49 TABLEBERG_DIR_PATH . 'build/row/block.json',
50 array(
51 'attributes' => $defaults->get_default_attributes( 'tableberg/row' ),
52 'render_callback' => array( $this, 'render_tableberg_row_block' ),
53 )
54 );
55 }
56 }
57