From 2740f7ab0fb563feca33aff9f9f6ac91fab07fb7 Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Tue, 27 Nov 2018 16:13:41 +0200 Subject: [PATCH 1/2] Tiled gallery block: load assets for the editor and view - Add wp-rich text dependency for tiled gallery --- class.jetpack-gutenberg.php | 1 + modules/tiled-gallery/tiled-gallery.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/class.jetpack-gutenberg.php b/class.jetpack-gutenberg.php index d94c605d4f766..c0d576544a99b 100644 --- a/class.jetpack-gutenberg.php +++ b/class.jetpack-gutenberg.php @@ -320,6 +320,7 @@ public static function enqueue_block_editor_assets() { 'wp-i18n', 'wp-keycodes', 'wp-plugins', + 'wp-rich-text', 'wp-token-list', 'wp-url', ), diff --git a/modules/tiled-gallery/tiled-gallery.php b/modules/tiled-gallery/tiled-gallery.php index 4e81a8c098dce..b93854addca02 100644 --- a/modules/tiled-gallery/tiled-gallery.php +++ b/modules/tiled-gallery/tiled-gallery.php @@ -17,6 +17,30 @@ public function __construct() { add_filter( 'jetpack_gallery_types', array( $this, 'jetpack_gallery_types' ), 9 ); add_filter( 'jetpack_default_gallery_type', array( $this, 'jetpack_default_gallery_type' ) ); + jetpack_register_block( + 'tiled-gallery', + array( + 'render_callback' => array( $this, 'load_block_assets' ), + ) + ); + } + + /** + * Tiled gallery block registration/dependency declaration. + * + * @param array $attr - Array containing the block attributes. + * @param string $content - String containing the block content. + * + * @return string + */ + public function load_block_assets( $attr, $content ) { + $dependencies = array( + 'lodash', + 'wp-i18n', + 'wp-token-list', + ); + Jetpack_Gutenberg::load_assets_as_required( 'tiled-gallery', $dependencies ); + return $content; } public function tiles_enabled() { From 382e9c8ec1748e243e26bd805bcdb1224e4a665d Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Wed, 28 Nov 2018 09:56:32 -0800 Subject: [PATCH 2/2] lets load the blocks later so that when modules are added on init 10 things still work as expected. --- class.jetpack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class.jetpack.php b/class.jetpack.php index 0f364b108814a..fe6ebf070c8d0 100644 --- a/class.jetpack.php +++ b/class.jetpack.php @@ -537,7 +537,7 @@ private function __construct() { * Prepare Gutenberg Editor functionality */ require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php'; - add_action( 'init', array( 'Jetpack_Gutenberg', 'load_blocks' ) ); // Registers all the Jetpack blocks . + add_action( 'init', array( 'Jetpack_Gutenberg', 'load_blocks' ), 99 ); // Registers all the Jetpack blocks . add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); add_filter( 'jetpack_set_available_blocks', array( 'Jetpack_Gutenberg', 'jetpack_set_available_blocks' ) );