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 / Cell.php

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

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