| 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 |
|