| 1 |
<?php |
| 2 |
|
| 3 |
namespace Leadin\admin; |
| 4 |
|
| 5 |
use Leadin\AssetsManager; |
| 6 |
use Leadin\utils\Versions; |
| 7 |
|
| 8 |
/** |
| 9 |
* Contains all the methods used to initialize Gutenberg blocks. |
| 10 |
*/ |
| 11 |
class Gutenberg { |
| 12 |
/** |
| 13 |
* Class constructor, register Gutenberg blocks. |
| 14 |
*/ |
| 15 |
public function __construct() { |
| 16 |
if ( ! function_exists( 'register_block_type' ) ) { |
| 17 |
// Gutenberg is not active. |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
add_action( 'init', array( $this, 'register_gutenberg_block' ) ); |
| 22 |
add_filter( 'block_categories_all', array( $this, 'add_hubspot_category' ) ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Add HubSpot category to Gutenberg blocks. |
| 27 |
* |
| 28 |
* @param Array $categories Array of block categories. |
| 29 |
*/ |
| 30 |
public function add_hubspot_category( $categories ) { |
| 31 |
return array_merge( |
| 32 |
$categories, |
| 33 |
array( |
| 34 |
array( |
| 35 |
'slug' => 'leadin-blocks', |
| 36 |
'title' => __( 'HubSpot', 'leadin' ), |
| 37 |
), |
| 38 |
) |
| 39 |
); |
| 40 |
} |
| 41 |
/** |
| 42 |
* Register HubSpot Form Gutenberg block. |
| 43 |
*/ |
| 44 |
public function register_gutenberg_block() { |
| 45 |
AssetsManager::localize_gutenberg(); |
| 46 |
register_block_type( |
| 47 |
'leadin/hubspot-blocks', |
| 48 |
array( |
| 49 |
'editor_script' => AssetsManager::GUTENBERG, |
| 50 |
) |
| 51 |
); |
| 52 |
} |
| 53 |
} |
| 54 |
|