assertStringContainsString( 'style="color: #111;"', $rendered_block );
+ $this->assertStringContainsString( 'aria-hidden="true"', $rendered_block );
+ $this->assertStringContainsString( '
', $rendered_block );
+ $this->assertStringContainsString( '
assertStringContainsString( 'viewBox="0 0 100 10"', $rendered_block );
+ $this->assertStringContainsString( 'xmlns="http://www.w3.org/2000/svg"', $rendered_block );
+ $this->assertStringContainsString( 'preserveAspectRatio="none"', $rendered_block );
+ $this->assertStringContainsString( 'assertStringContainsString( 'fillRule="evenodd"', $rendered_block );
+ $this->assertStringContainsString( 'transform="matrix(1 0 0 -1 0 10)"', $rendered_block );
+ $this->assertStringContainsString( '
', $rendered_block );
+
+ }
+}
diff --git a/.dev/tests/phpunit/src/blocks/social/test-index.php b/.dev/tests/phpunit/src/blocks/social/test-share-block.php
similarity index 69%
rename from .dev/tests/phpunit/src/blocks/social/test-index.php
rename to .dev/tests/phpunit/src/blocks/social/test-share-block.php
index 960a491d2ef..d136563b5ea 100644
--- a/.dev/tests/phpunit/src/blocks/social/test-index.php
+++ b/.dev/tests/phpunit/src/blocks/social/test-share-block.php
@@ -1,6 +1,6 @@
fail( "$action_data[0] is not attached to $action_data[1]." );
-
- }
- }
-
- $this->assertTrue( true );
-
- }
/**
* Test the social block markup returns correctly
*/
public function test_coblocks_render_share_block() {
- $attributes = [
+ $attributes = array(
'className' => 'test-class-name',
'size' => 'large',
'hasColors' => true,
- ];
+ );
- $this->assertEquals( '', coblocks_render_share_block( $attributes ) );
+ $this->assertEquals( '', coblocks_render_coblocks_social_block( $attributes ) );
}
@@ -76,12 +51,12 @@ public function test_coblocks_render_share_block() {
*/
public function test_coblocks_render_share_block_style_mask() {
- $attributes = [
+ $attributes = array(
'className' => 'test-class-name is-style-mask',
'hasColors' => true,
- ];
+ );
- $this->assertEquals( '', coblocks_render_share_block( $attributes ) );
+ $this->assertEquals( '', coblocks_render_coblocks_social_block( $attributes ) );
}
@@ -90,11 +65,11 @@ public function test_coblocks_render_share_block_style_mask() {
*/
public function test_coblocks_render_share_block_platforms() {
- $attributes = [
+ $attributes = array(
'twitter' => true,
- ];
+ );
- $this->assertMatchesRegularExpression( '//', coblocks_render_share_block( $attributes ) );
+ $this->assertMatchesRegularExpression( '/ /', coblocks_render_coblocks_social_block( $attributes ) );
}
- /**
- * Test the share block is registered
- *
- * @expectedIncorrectUsage WP_Block_Type_Registry::register
- */
- public function test_coblocks_register_share_block() {
-
- coblocks_register_share_block();
-
- $expected_registered_blocks = [
- 'coblocks/social',
- ];
+ public function test_phone_field_block_registered() {
$registered_blocks = WP_Block_Type_Registry::get_instance()->get_all_registered();
- foreach ( $expected_registered_blocks as $coblocks_block ) {
-
- if ( ! array_key_exists( $coblocks_block, $registered_blocks ) ) {
+ $this->assertArrayHasKey( 'coblocks/social', $registered_blocks );
- $this->fail( "$coblocks_block is not registered." );
-
- }
- }
+ }
- $this->assertTrue( true );
+ /**
+ * Test the social block markup returns correctly with custom block background color
+ */
+ public function test_coblocks_render_share_block_custom_block_background_color() {
+ $attributes = array(
+ 'customBlockBackgroundColor' => '#123456',
+ 'hasColors' => true,
+ );
+ $this->assertMatchesRegularExpression( '//', coblocks_render_coblocks_social_block( $attributes ) );
}
}
diff --git a/.dev/tests/phpunit/src/extensions/layout-selector/test-index.php b/.dev/tests/phpunit/src/extensions/layout-selector/test-index.php
index 3aca5707aad..3fe3bf28ff5 100644
--- a/.dev/tests/phpunit/src/extensions/layout-selector/test-index.php
+++ b/.dev/tests/phpunit/src/extensions/layout-selector/test-index.php
@@ -10,7 +10,7 @@ public static function set_up_before_class() {
require_once COBLOCKS_PLUGIN_DIR . 'src/extensions/layout-selector/index.php';
}
- public function set_up(): void {
+ public function set_up(): void {
parent::set_up();
set_current_screen( 'dashboard' );
@@ -18,7 +18,7 @@ public function set_up(): void {
// Reset queued scripts and styles.
global $wp_scripts, $wp_styles;
$wp_scripts = new WP_Scripts();
- $wp_styles = new WP_Styles();
+ $wp_styles = new WP_Styles();
}
public function tear_down(): void {
@@ -49,7 +49,12 @@ public function test_categories_can_be_filtered() {
add_filter(
'coblocks_layout_selector_categories',
function() {
- return array( array( 'slug' => 'filtered', 'title' => 'filtered' ) );
+ return array(
+ array(
+ 'slug' => 'filtered',
+ 'title' => 'filtered',
+ ),
+ );
}
);
@@ -90,7 +95,7 @@ function() {
'category' => 'testing',
'label' => 'testing',
'blocks' => array(),
- )
+ ),
);
}
);
@@ -121,7 +126,7 @@ public function test_layout_selector_is_localized() {
coblocks_localize_layout_selector();
$localized = $wp_scripts->get_data( 'coblocks-editor', 'data' );
- $layouts = coblocks_layout_selector_layouts();
+ $layouts = coblocks_layout_selector_layouts();
$categories = coblocks_layout_selector_categories();
$this->assertStringContainsString( 'var coblocksLayoutSelector', $localized );
diff --git a/class-coblocks.php b/class-coblocks.php
index 3e3e9a50592..016ae0f0624 100644
--- a/class-coblocks.php
+++ b/class-coblocks.php
@@ -110,7 +110,6 @@ private function includes() {
require_once COBLOCKS_PLUGIN_DIR . 'includes/class-coblocks-register-blocks.php';
require_once COBLOCKS_PLUGIN_DIR . 'includes/class-coblocks-generated-styles.php';
require_once COBLOCKS_PLUGIN_DIR . 'includes/class-coblocks-body-classes.php';
- require_once COBLOCKS_PLUGIN_DIR . 'includes/class-coblocks-form.php';
require_once COBLOCKS_PLUGIN_DIR . 'includes/class-coblocks-font-loader.php';
require_once COBLOCKS_PLUGIN_DIR . 'includes/class-coblocks-post-meta.php';
require_once COBLOCKS_PLUGIN_DIR . 'includes/class-coblocks-google-map-block.php';
diff --git a/includes/class-coblocks-block-assets.php b/includes/class-coblocks-block-assets.php
index b3dc5ee378d..3d2e7ff91e9 100644
--- a/includes/class-coblocks-block-assets.php
+++ b/includes/class-coblocks-block-assets.php
@@ -17,6 +17,12 @@
*/
class CoBlocks_Block_Assets {
+ /**
+ * This plugin's assets path.
+ *
+ * @var CoBlocks_Block_Assets
+ */
+ private $assets_dir = '';
/**
* This plugin's instance.
@@ -42,12 +48,15 @@ public static function register() {
* The Constructor.
*/
public function __construct() {
+ $this->assets_dir = CoBlocks()->asset_source( 'js' );
add_action( 'enqueue_block_assets', array( $this, 'block_assets' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'editor_assets' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'frontend_scripts' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_action( 'save_post_wp_template_part', array( $this, 'clear_template_transients' ) );
- add_action( 'wp_enqueue_scripts', array( $this, 'frontend_only_scripts' ) );
+
+ // `render_block` filters must be applied early.
+ add_filter( 'render_block', array( $this, 'coblocks_enqueue_scripts_for_core_blocks' ), 10, 2 );
}
/**
@@ -69,29 +78,6 @@ public function get_asset_file( $filepath ) {
);
}
- /**
- * Enqueue scripts that should only be available on the front end
- */
- public function frontend_only_scripts() {
- // Define where the asset is loaded from.
- $dir = CoBlocks()->asset_source( 'js' );
-
- // Define where the vendor asset is loaded from.
- $vendors_dir = CoBlocks()->asset_source( 'js/vendors' );
-
- // Gist block.
- // only want this loading in front end.
- if ( has_block( 'coblocks/gist' ) || has_block( 'core/embed' ) ) {
- wp_enqueue_script(
- 'coblocks-gist',
- $dir . 'coblocks-gist.js',
- array(),
- COBLOCKS_VERSION,
- true
- );
- }
- }
-
/**
* Enqueue block assets for use within Gutenberg.
*
@@ -153,7 +139,7 @@ public function block_assets() {
$asset_file = $this->get_asset_file( $filepath );
$rtl = ! is_rtl() ? '' : '-rtl';
- wp_enqueue_style(
+ wp_register_style(
'coblocks-frontend',
COBLOCKS_PLUGIN_URL . $filepath . $rtl . '.css',
array(),
@@ -188,7 +174,7 @@ public function editor_assets() {
$asset_file = $this->get_asset_file( $filepath );
$rtl = ! is_rtl() ? '' : '-rtl';
- wp_enqueue_style(
+ wp_register_style(
'coblocks-editor',
COBLOCKS_PLUGIN_URL . $filepath . $rtl . '.css',
array(),
@@ -213,7 +199,7 @@ public function editor_assets() {
add_filter( 'coblocks_patterns_show_settings_panel', '__return_false' );
}
- wp_enqueue_script(
+ wp_register_script(
'coblocks-editor',
COBLOCKS_PLUGIN_URL . $filepath . '.js',
array_merge( $asset_file['dependencies'], array( 'wp-api' ) ),
@@ -240,7 +226,7 @@ public function editor_assets() {
}
}
- wp_enqueue_script(
+ wp_register_script(
$name,
COBLOCKS_PLUGIN_URL . $filepath . '.js',
array_merge( $asset_file['dependencies'], array( 'wp-api', 'coblocks-editor' ) ),
@@ -398,9 +384,6 @@ public function frontend_scripts() {
return;
}
- // Define where the asset is loaded from.
- $dir = CoBlocks()->asset_source( 'js' );
-
// Define where the vendor asset is loaded from.
$vendors_dir = CoBlocks()->asset_source( 'js/vendors' );
@@ -410,37 +393,43 @@ public function frontend_scripts() {
// Enqueue for coblocks animations.
wp_enqueue_script(
'coblocks-animation',
- $dir . 'coblocks-animation.js',
+ $this->assets_dir . 'coblocks-animation.js',
array(),
COBLOCKS_VERSION,
true
);
- // Masonry block.
+ // Masonry v1 block scripts.
if ( $this->has_masonry_v1_block() ) {
wp_enqueue_script(
'coblocks-masonry',
- $dir . 'coblocks-masonry.js',
+ $this->assets_dir . 'coblocks-masonry.js',
array( 'jquery', 'masonry', 'imagesloaded' ),
COBLOCKS_VERSION,
true
);
}
- // Carousel block.
- if ( $this->is_page_gutenberg() || has_block( 'coblocks/gallery-carousel' ) || has_block( 'core/block' ) ) {
- wp_enqueue_script(
- 'coblocks-tiny-swiper',
- $vendors_dir . 'tiny-swiper.js',
- array(),
- COBLOCKS_VERSION,
- true
- );
- }
+ wp_register_script(
+ 'coblocks-gist-script',
+ $this->assets_dir . 'coblocks-gist-script.js',
+ array(),
+ COBLOCKS_VERSION,
+ true
+ );
- wp_enqueue_script(
+ // Carousel block scripts.
+ wp_register_script(
+ 'coblocks-tiny-swiper',
+ $vendors_dir . 'tiny-swiper.js',
+ array(),
+ COBLOCKS_VERSION,
+ true
+ );
+
+ wp_register_script(
'coblocks-tinyswiper-initializer',
- $dir . 'coblocks-tinyswiper-initializer.js',
+ $this->assets_dir . 'coblocks-tinyswiper-initializer.js',
array(),
COBLOCKS_VERSION,
true
@@ -456,90 +445,142 @@ public function frontend_scripts() {
)
);
- // Post Carousel block.
- if ( $this->is_page_gutenberg() || has_block( 'coblocks/post-carousel' ) || has_block( 'core/block' ) ) {
- wp_enqueue_script(
- 'coblocks-post-carousel',
- $dir . 'coblocks-post-carousel.js',
- array(),
- COBLOCKS_VERSION,
- true
- );
+ // Post Carousel block script.
+ wp_register_script(
+ 'coblocks-post-carousel',
+ $this->assets_dir . 'coblocks-post-carousel.js',
+ array(),
+ COBLOCKS_VERSION,
+ true
+ );
- wp_localize_script(
- 'coblocks-post-carousel',
- 'coblocksPostCarousel',
- array(
- 'carouselPrevButtonAriaLabel' => $previous_aria_label,
- 'carouselNextButtonAriaLabel' => $next_aria_label,
- )
- );
- }
+ wp_localize_script(
+ 'coblocks-post-carousel',
+ 'coblocksPostCarousel',
+ array(
+ 'carouselPrevButtonAriaLabel' => $previous_aria_label,
+ 'carouselNextButtonAriaLabel' => $next_aria_label,
+ )
+ );
// Events block.
- if ( $this->is_page_gutenberg() || has_block( 'coblocks/events' ) || has_block( 'core/block' ) ) {
- wp_enqueue_script(
- 'coblocks-events',
- $dir . 'coblocks-events.js',
- array(),
- COBLOCKS_VERSION,
- true
- );
+ wp_register_script(
+ 'coblocks-events',
+ $this->assets_dir . 'coblocks-events.js',
+ array(),
+ COBLOCKS_VERSION,
+ true
+ );
- wp_localize_script(
- 'coblocks-events',
- 'coblocksEvents',
- array(
- 'carouselPrevButtonAriaLabel' => $previous_aria_label,
- 'carouselNextButtonAriaLabel' => $next_aria_label,
- )
- );
- }
+ wp_localize_script(
+ 'coblocks-events',
+ 'coblocksEvents',
+ array(
+ 'carouselPrevButtonAriaLabel' => $previous_aria_label,
+ 'carouselNextButtonAriaLabel' => $next_aria_label,
+ )
+ );
// Counter block.
- if ( $this->is_page_gutenberg() || has_block( 'coblocks/counter' ) || has_block( 'core/block' ) ) {
- $asset_file = $this->get_asset_file( 'dist/js/coblocks-counter' );
- wp_enqueue_script(
- 'coblocks-counter-script',
- $dir . 'coblocks-counter.js',
- $asset_file['dependencies'],
- COBLOCKS_VERSION,
- true
- );
- }
+ $asset_file = $this->get_asset_file( 'dist/js/coblocks-counter-script' );
+ wp_register_script(
+ 'coblocks-counter-script',
+ $this->assets_dir . 'coblocks-counter-script.js',
+ $asset_file['dependencies'],
+ COBLOCKS_VERSION,
+ true
+ );
// Services block.
- if ( $this->is_page_gutenberg() || has_block( 'coblocks/services' ) ) {
- $asset_file = $this->get_asset_file( 'dist/js/coblocks-services' );
+ $asset_file = $this->get_asset_file( 'dist/js/coblocks-services-script' );
+ wp_register_script(
+ 'coblocks-services-script',
+ $this->assets_dir . 'coblocks-services-script.js',
+ $asset_file['dependencies'],
+ COBLOCKS_VERSION,
+ true
+ );
+
+ $this->localize_lightbox_controls();
+
+ }
+
+ /**
+ * Enqueue specific scripts for the given core blocks.
+ *
+ * @param string $block_content The block content to be rendered.
+ * @param array $block The block attributes.
+ *
+ * @return string The original block content.
+ */
+ public function coblocks_enqueue_scripts_for_core_blocks( $block_content, $block ) {
+
+ // Bail if block does not have name, or does not have attributes.
+ if ( ! isset( $block['blockName'] ) || ! isset( $block['attrs'] ) ) {
+ return $block_content;
+ }
+
+ $block_name = $block['blockName'];
+ $block_attributes = $block['attrs'];
+
+ // Allowed blocks for the lightbox script.
+ $lightbox_allowed_blocks = array(
+ 'core/gallery',
+ 'core/image',
+ 'core/block',
+ );
+
+ if ( in_array( $block_name, $lightbox_allowed_blocks, true ) &&
+ // Has a lightbox attribute set to true.
+ (
+ isset( $block_attributes['lightbox'] ) &&
+ true === $block_attributes['lightbox']
+ )
+ ) {
+
wp_enqueue_script(
- 'coblocks-services-script',
- $dir . 'coblocks-services.js',
- $asset_file['dependencies'],
+ 'coblocks-lightbox',
+ $this->assets_dir . 'coblocks-lightbox.js',
+ array(),
COBLOCKS_VERSION,
true
);
+
+ // Script must be localized after the 'handle' script is registered.
+ // `coblocks-lightbox` is the handle that is shared between the scripts.
+ $this->localize_lightbox_controls();
+
+ wp_enqueue_style( 'coblocks-frontend' );
}
- // Lightbox.
- if (
- has_block( 'coblocks/gallery-masonry' ) ||
- has_block( 'coblocks/gallery-stacked' ) ||
- has_block( 'coblocks/gallery-collage' ) ||
- has_block( 'coblocks/gallery-carousel' ) ||
- has_block( 'coblocks/gallery-offset' ) ||
- has_block( 'core/gallery' ) ||
- has_block( 'core/image' ) ||
- has_block( 'core/block' )
+ // Allowed blocks for the gist script.
+ $gist_allowed_blocks = array(
+ 'core/embed',
+ );
+
+ if ( in_array( $block_name, $gist_allowed_blocks, true ) &&
+ // Has a URL attribute with gist.github.com.
+ (
+ isset( $block_attributes['url'] ) &&
+ str_contains( $block_attributes['url'], 'gist.github.com' )
+ )
) {
wp_enqueue_script(
- 'coblocks-lightbox',
- $dir . 'coblocks-lightbox.js',
+ 'coblocks-gist-script',
+ $this->assets_dir . 'coblocks-gist-script.js',
array(),
COBLOCKS_VERSION,
true
);
}
+ return $block_content;
+ }
+
+ /**
+ * Localize language script for the lightbox controls.
+ */
+ private function localize_lightbox_controls() {
wp_localize_script(
'coblocks-lightbox',
'coblocksLightboxData',
diff --git a/includes/class-coblocks-form.php b/includes/class-coblocks-form.php
index cec3d829c1b..3c53289492c 100644
--- a/includes/class-coblocks-form.php
+++ b/includes/class-coblocks-form.php
@@ -69,8 +69,6 @@ public function default_success_text() {
public function __construct() {
add_action( 'init', array( $this, 'register_settings' ) );
- add_action( 'init', array( $this, 'register_form_blocks' ) );
-
add_action( 'wp_enqueue_scripts', array( $this, 'form_recaptcha_assets' ) );
}
@@ -144,52 +142,6 @@ public function form_recaptcha_assets() {
}
- /**
- * Register the form blocks.
- */
- public function register_form_blocks() {
-
- register_block_type(
- 'coblocks/form',
- array(
- 'render_callback' => array( $this, 'render_form' ),
- )
- );
-
- $form_blocks = array(
- 'name',
- 'email',
- 'textarea',
- 'text',
- 'date',
- 'phone',
- 'radio',
- 'select',
- 'submit-button',
- 'checkbox',
- 'website',
- 'hidden',
- );
-
- foreach ( $form_blocks as $form_block ) {
-
- register_block_type(
- "coblocks/field-{$form_block}",
- array(
- 'parent' => array( 'coblocks/form' ),
- 'render_callback' => array( $this, sprintf( 'render_field_%s', str_replace( '-', '_', $form_block ) ) ),
- )
- );
-
- }
-
- /**
- * Fires when the coblocks/form block and sub-blocks are registered
- */
- do_action( 'coblocks_register_form_blocks' );
-
- }
-
/**
* Render the form
*
@@ -198,7 +150,7 @@ public function register_form_blocks() {
*
* @return mixed Form markup or success message when form submits successfully.
*/
- public function render_form( $atts, $content ) {
+ public function coblocks_render_coblocks_form_block( $atts, $content ) {
$this->form_hash = sha1( $content );
$submitted_hash = filter_input( INPUT_POST, 'form-hash' );
@@ -232,7 +184,7 @@ public function render_form( $atts, $content ) {
render_field_submit_button( $atts );
+ echo $this->coblocks_render_coblocks_field_submit_button_block( $atts );
endif;
?>
@@ -251,7 +203,7 @@ public function render_form( $atts, $content ) {
*
* @return mixed Markup for the name field.
*/
- public function render_field_name( $atts ) {
+ public function coblocks_render_coblocks_field_name_block( $atts ) {
static $name_count = 1;
@@ -316,7 +268,7 @@ public function render_field_name( $atts ) {
*
* @return mixed Markup for the email field.
*/
- public function render_field_email( $atts ) {
+ public function coblocks_render_coblocks_field_email_block( $atts ) {
$label = isset( $atts['label'] ) ? $atts['label'] : __( 'Email', 'coblocks' );
$label_slug = sanitize_title( $label );
@@ -344,7 +296,7 @@ public function render_field_email( $atts ) {
*
* @return mixed Markup for the textarea field.
*/
- public function render_field_textarea( $atts ) {
+ public function coblocks_render_coblocks_field_textarea_block( $atts ) {
static $textarea_count = 1;
@@ -375,7 +327,7 @@ public function render_field_textarea( $atts ) {
*
* @return mixed Markup for the text field.
*/
- public function render_field_text( $atts ) {
+ public function coblocks_render_coblocks_field_text_block( $atts ) {
static $text_count = 1;
@@ -406,7 +358,7 @@ public function render_field_text( $atts ) {
*
* @return mixed Markup for the date field.
*/
- public function render_field_date( $atts ) {
+ public function coblocks_render_coblocks_field_date_block( $atts ) {
static $date_count = 1;
@@ -437,7 +389,7 @@ public function render_field_date( $atts ) {
*
* @return mixed Markup for the phone field.
*/
- public function render_field_phone( $atts ) {
+ public function coblocks_render_coblocks_field_phone_block( $atts ) {
static $phone_count = 1;
@@ -468,7 +420,7 @@ public function render_field_phone( $atts ) {
*
* @return mixed Markup for the radio field.
*/
- public function render_field_radio( $atts ) {
+ public function coblocks_render_coblocks_field_radio_block( $atts ) {
if ( empty( $atts['options'] ) ) {
@@ -539,7 +491,7 @@ public function render_field_radio( $atts ) {
*
* @return mixed Markup for the select field.
*/
- public function render_field_select( $atts ) {
+ public function coblocks_render_coblocks_field_select_block( $atts ) {
if ( empty( $atts['options'] ) ) {
@@ -588,7 +540,7 @@ public function render_field_select( $atts ) {
*
* @return mixed Markup for the checkbox field.
*/
- public function render_field_checkbox( $atts ) {
+ public function coblocks_render_coblocks_field_checkbox_block( $atts ) {
if ( empty( $atts['options'] ) ) {
@@ -678,7 +630,7 @@ public function render_field_checkbox( $atts ) {
*
* @return mixed Markup for the website field.
*/
- public function render_field_website( $atts ) {
+ public function coblocks_render_coblocks_field_website_block( $atts ) {
static $website_count = 1;
@@ -709,7 +661,7 @@ public function render_field_website( $atts ) {
*
* @return mixed Markup for the hidden field.
*/
- public function render_field_hidden( $atts ) {
+ public function coblocks_render_coblocks_field_hidden_block( $atts ) {
static $hidden_count = 1;
@@ -794,7 +746,7 @@ public function render_field_label( $atts, $field_label, $count = 1 ) {
*
* @return mixed Form submit button markup.
*/
- public function render_field_submit_button( $atts ) {
+ public function coblocks_render_coblocks_field_submit_button_block( $atts ) {
$btn_text = isset( $atts['submitButtonText'] ) ? $atts['submitButtonText'] : __( 'Submit', 'coblocks' );
$btn_class = isset( $atts['className'] ) ? " {$atts['className']}" : '';
diff --git a/includes/class-coblocks-generated-styles.php b/includes/class-coblocks-generated-styles.php
index 719e7f4870c..fc6f0e7b362 100644
--- a/includes/class-coblocks-generated-styles.php
+++ b/includes/class-coblocks-generated-styles.php
@@ -56,7 +56,7 @@ public function enqueue_styles() {
if ( is_null( $styles ) ) {
return;
}
- wp_add_inline_style( 'coblocks-frontend', $styles );
+ wp_add_inline_style( 'coblocks-frontend-inline', $styles );
}
/**
diff --git a/includes/class-coblocks-register-blocks.php b/includes/class-coblocks-register-blocks.php
index c087a960fd8..21a94a10f3f 100644
--- a/includes/class-coblocks-register-blocks.php
+++ b/includes/class-coblocks-register-blocks.php
@@ -25,6 +25,13 @@ class CoBlocks_Register_Blocks {
*/
private static $instance;
+ /**
+ * This plugin's CoBlocks Form class instance.
+ *
+ * @var CoBlocks_Form
+ */
+ private static $coblocks_form;
+
/**
* Registers the plugin.
*
@@ -33,6 +40,9 @@ class CoBlocks_Register_Blocks {
public static function register() {
if ( null === self::$instance ) {
self::$instance = new CoBlocks_Register_Blocks();
+
+ require_once COBLOCKS_PLUGIN_DIR . 'includes/class-coblocks-form.php';
+ self::$coblocks_form = new CoBlocks_Form();
}
return self::$instance;
@@ -54,6 +64,79 @@ public function __construct() {
add_action( 'init', array( $this, 'register_blocks' ), 99 );
}
+ /**
+ * Get the path of the block metadata file (block.json) for a given block.
+ *
+ * @param string $block_name The name of the block to look for.
+ * @param bool $is_child_block A flag indicating whether the block is a child block or not.
+ *
+ * @return string|array The path to the block metadata file, or an array of paths if not found.
+ */
+ public function get_block_metadata_path( $block_name, $is_child_block ) {
+ $blocks_base_path = COBLOCKS_PLUGIN_DIR . 'src/blocks/';
+ $path_pattern = $is_child_block ? '*/' . $block_name . '/block.json' : $block_name . '/block.json';
+
+ $file_glob = glob( $blocks_base_path . $path_pattern, GLOB_NOSORT );
+
+ if ( $is_child_block && ! isset( $file_glob[0] ) ) {
+ $file_glob = glob( $blocks_base_path . '*/' . $path_pattern, GLOB_NOSORT );
+ }
+
+ return isset( $file_glob[0] ) ? $file_glob[0] : $file_glob;
+ }
+
+ /**
+ * Load block metadata from block.json file.
+ *
+ * @param string $block_name The name of the block.
+ * @param bool $is_child_block Optional. Set to true if it's a child block. Default false.
+ *
+ * @return array The block metadata or an empty JSON object if no content is found.
+ */
+ public function load_block_metadata( $block_name, $is_child_block = false ) {
+
+ $file_path = $this->get_block_metadata_path( $block_name, $is_child_block );
+ $metadata = json_decode( '{}', true );
+
+ if ( file_exists( $file_path ) ) {
+ ob_start();
+ include $file_path;
+ $file_metadata = json_decode( ob_get_clean(), true );
+ $metadata = $file_metadata;
+ }
+
+ return $metadata;
+ }
+
+ /**
+ * Build a block manifest. The resulting array is used to register blocks and parses block.json files.
+ * For now we need to collect the `render` property from the block.json files and require manually.
+ *
+ * @return array The block manifest or an empty array if no content is found.
+ */
+ public function load_block_manifest() {
+ $block_json_paths = array(
+ COBLOCKS_PLUGIN_DIR . 'src/blocks/*/block.json',
+ COBLOCKS_PLUGIN_DIR . 'src/blocks/*/*/block.json',
+ COBLOCKS_PLUGIN_DIR . 'src/blocks/form/fields/*/block.json',
+ );
+
+ $manifest = array();
+ foreach ( $block_json_paths as $block_json_path ) {
+ $block_json_files = glob( $block_json_path, GLOB_NOSORT );
+ foreach ( $block_json_files as $block_json_file ) {
+ $block_json = json_decode( file_get_contents( $block_json_file ), true );
+ $manifest[ $block_json['name'] ]['path'] = str_replace( '/block.json', '', $block_json_file );
+
+ if ( isset( $block_json['render'] ) ) {
+ $manifest[ $block_json['name'] ]['render_callback'] = $block_json['render'];
+ }
+ }
+ }
+
+ return $manifest;
+ }
+
/**
* Add actions to enqueue assets.
*
@@ -67,88 +150,47 @@ public function register_blocks() {
}
// Shortcut for the slug.
- $slug = $this->slug;
-
- register_block_type(
- $slug . '/accordion',
- array(
- 'editor_script' => $slug . '-editor',
- 'editor_style' => $slug . '-editor',
- 'style' => $slug . '-frontend',
- )
- );
- register_block_type(
- $slug . '/alert',
- array(
- 'editor_script' => $slug . '-editor',
- 'editor_style' => $slug . '-editor',
- 'style' => $slug . '-frontend',
- )
- );
- register_block_type(
- $slug . '/author',
- array(
- 'editor_script' => $slug . '-editor',
- 'editor_style' => $slug . '-editor',
- 'style' => $slug . '-frontend',
- )
- );
- register_block_type(
- $slug . '/click-to-tweet',
- array(
- 'editor_script' => $slug . '-editor',
- 'editor_style' => $slug . '-editor',
- 'style' => $slug . '-frontend',
- )
- );
- register_block_type(
- $slug . '/dynamic-separator',
- array(
- 'editor_script' => $slug . '-editor',
- 'editor_style' => $slug . '-editor',
- 'style' => $slug . '-frontend',
- )
- );
- register_block_type(
- $slug . '/gif',
- array(
- 'editor_script' => $slug . '-editor',
- 'editor_style' => $slug . '-editor',
- 'style' => $slug . '-frontend',
- )
- );
- register_block_type(
- $slug . '/highlight',
- array(
- 'editor_script' => $slug . '-editor',
- 'editor_style' => $slug . '-editor',
- 'style' => $slug . '-frontend',
- )
- );
- register_block_type(
- $slug . '/gallery-carousel',
- array(
- 'editor_script' => $slug . '-editor',
- 'editor_style' => $slug . '-editor',
- 'style' => $slug . '-frontend',
- )
- );
- register_block_type(
- $slug . '/gallery-masonry',
- array(
- 'editor_script' => $slug . '-editor',
- 'editor_style' => $slug . '-editor',
- 'style' => $slug . '-frontend',
- )
- );
- register_block_type(
- $slug . '/gallery-stacked',
- array(
- 'editor_script' => $slug . '-editor',
- 'editor_style' => $slug . '-editor',
- 'style' => $slug . '-frontend',
- )
- );
+ $slug = $this->slug;
+ $blocks = $this->load_block_manifest();
+ foreach ( $blocks as $block_name => $block_options ) {
+
+ // Bulk styles for blocks. `style-coblocks-1` AKA `coblocks-frontend`.
+ // We need to split the styles and specify the handle for each block in the block.json file.
+ // For now we have all style files combined into either editor or frontend styles.
+ $default_options = array(
+ 'editor_style' => $slug . '-editor',
+ 'style' => $slug . '-frontend',
+ );
+
+ // Block has a render_callback defined.
+ if ( isset( $block_options['render_callback'] ) ) {
+
+ // Include the render_callback.
+ $render_callback_require_path = $block_options['path'] . '/' . $block_options['render_callback'];
+ if ( file_exists( $render_callback_require_path ) ) {
+ require_once $render_callback_require_path;
+ }
+ $render_callback_block_name = str_replace( array( '-', '/' ), array( '_', '_' ), $block_name );
+ $render_callback_handle = "coblocks_render_{$render_callback_block_name}_block";
+
+ // Most SSR blocks have render_callback defined in the block index.php.
+ if ( function_exists( $render_callback_handle ) ) {
+ $default_options['render_callback'] = $render_callback_handle;
+ }
+
+ // Some blocks like Form and child Field blocks have render_callback defined in the CoBlocks_Form class.
+ if ( class_exists( 'CoBlocks_Form' ) && method_exists( 'CoBlocks_Form', $render_callback_handle ) ) {
+ $default_options['render_callback'] = array( self::$coblocks_form, $render_callback_handle );
+ }
+ }
+
+ // Register the block.
+ register_block_type(
+ $block_options['path'] . '/block.json',
+ $default_options
+ );
+
+ }
}
}
diff --git a/src/blocks-3.js b/src/blocks-3.js
index 9fcaa3fa811..b8b00c3fb45 100644
--- a/src/blocks-3.js
+++ b/src/blocks-3.js
@@ -1,27 +1,25 @@
import { registerBlock } from './utils/helper';
// Register Blocks
-import * as clickToTweet from './blocks/click-to-tweet';
-import * as collage from './blocks/gallery-collage';
-import * as fieldCheckbox from './blocks/form/fields/checkbox';
-import * as fieldDate from './blocks/form/fields/date';
-import * as fieldEmail from './blocks/form/fields/email';
-import * as fieldHidden from './blocks/form/fields/hidden';
-import * as fieldName from './blocks/form/fields/name';
-import * as fieldRadio from './blocks/form/fields/radio';
-import * as fieldSelect from './blocks/form/fields/select';
-import * as fieldSubmitButton from './blocks/form/fields/submit-button';
-import * as fieldTelephone from './blocks/form/fields/phone';
-import * as fieldText from './blocks/form/fields/text';
-import * as fieldTextarea from './blocks/form/fields/textarea';
-import * as fieldWebsite from './blocks/form/fields/website';
+import * as form from './blocks/form';
+import * as fieldCheckbox from './blocks/form/fields/field-checkbox';
+import * as fieldDate from './blocks/form/fields/field-date';
+import * as fieldEmail from './blocks/form/fields/field-email';
+import * as fieldHidden from './blocks/form/fields/field-hidden';
+import * as fieldName from './blocks/form/fields/field-name';
+import * as fieldRadio from './blocks/form/fields/field-radio';
+import * as fieldSelect from './blocks/form/fields/field-select';
+import * as fieldSubmitButton from './blocks/form/fields/field-submit-button';
+import * as fieldTelephone from './blocks/form/fields/field-phone';
+import * as fieldText from './blocks/form/fields/field-text';
+import * as fieldTextarea from './blocks/form/fields/field-textarea';
+import * as fieldWebsite from './blocks/form/fields/field-website';
/**
* Function to register blocks provided by CoBlocks.
*/
[
- clickToTweet,
- collage,
+ form,
fieldDate,
fieldEmail,
fieldName,
diff --git a/src/blocks-4.js b/src/blocks-4.js
index 527bea76c0e..f0549e72d6b 100644
--- a/src/blocks-4.js
+++ b/src/blocks-4.js
@@ -1,15 +1,17 @@
import { registerBlock } from './utils/helper';
// Register Blocks
+import * as clickToTweet from './blocks/click-to-tweet';
+import * as collage from './blocks/gallery-collage';
import * as foodAndDrinks from './blocks/food-and-drinks';
import * as foodItem from './blocks/food-and-drinks/food-item';
-import * as form from './blocks/form';
/**
* Function to register blocks provided by CoBlocks.
*/
[
+ clickToTweet,
+ collage,
foodAndDrinks,
foodItem,
- form,
].forEach( registerBlock );
diff --git a/src/blocks/accordion/accordion-item/block.json b/src/blocks/accordion/accordion-item/block.json
index ac0e1add737..0b04124f8cb 100644
--- a/src/blocks/accordion/accordion-item/block.json
+++ b/src/blocks/accordion/accordion-item/block.json
@@ -28,7 +28,7 @@
},
"title": "Accordion Item",
"textdomain": "coblocks",
- "editorScript": "blocks-1",
"description": "Add collapsable accordion items to accordions.",
+ "editorScript": ["coblocks-1"],
"parent": [ "coblocks/accordion" ]
}
diff --git a/src/blocks/accordion/block.json b/src/blocks/accordion/block.json
index d6d5751246f..ef46fef1b78 100644
--- a/src/blocks/accordion/block.json
+++ b/src/blocks/accordion/block.json
@@ -13,6 +13,6 @@
},
"title": "Accordion",
"textdomain": "coblocks",
- "editorScript": "blocks-1",
+ "editorScript": ["coblocks-1"],
"description": "Organize content within collapsable accordion items."
}
diff --git a/src/blocks/alert/block.json b/src/blocks/alert/block.json
index 9604ce13c00..bf000b5df39 100644
--- a/src/blocks/alert/block.json
+++ b/src/blocks/alert/block.json
@@ -1,6 +1,5 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
- "apiVersion": 2,
"name": "coblocks/alert",
"attributes": {
"content": {
@@ -13,6 +12,7 @@
}
},
"textdomain": "coblocks",
+ "editorScript": ["coblocks-1"],
"title": "Alert",
"category": "theme"
-}
\ No newline at end of file
+}
diff --git a/src/blocks/author/block.json b/src/blocks/author/block.json
index 57d71ec21d3..9a14daf4116 100644
--- a/src/blocks/author/block.json
+++ b/src/blocks/author/block.json
@@ -1,6 +1,5 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
- "apiVersion": 2,
"name": "coblocks/author",
"attributes": {
"biography": {
@@ -43,6 +42,6 @@
}
},
"title": "Author",
- "editorScript": "blocks-1",
- "category": "theme"
-}
\ No newline at end of file
+ "category": "theme",
+ "editorScript": ["coblocks-1"]
+}
diff --git a/src/blocks/buttons/block.json b/src/blocks/buttons/block.json
index d482cf8f47b..259402f4121 100644
--- a/src/blocks/buttons/block.json
+++ b/src/blocks/buttons/block.json
@@ -17,6 +17,5 @@
},
"title": "Buttons (Deprecated)",
"textdomain": "coblocks",
- "editorScript": "blocks-1",
"description": "This block is replaced by core Buttons block."
}
diff --git a/src/blocks/click-to-tweet/block.json b/src/blocks/click-to-tweet/block.json
index c07ee7b7390..fae31f9bbd0 100644
--- a/src/blocks/click-to-tweet/block.json
+++ b/src/blocks/click-to-tweet/block.json
@@ -1,6 +1,6 @@
{
- "$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
+ "$schema": "https://schemas.wp.org/trunk/block.json",
"name": "coblocks/click-to-tweet",
"category": "formatting",
"attributes": {
@@ -50,6 +50,6 @@
},
"title": "Click to Tweet",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
+ "editorScript": ["coblocks-4"],
"description": "Add a quote for readers to tweet via Twitter."
}
diff --git a/src/blocks/counter/block.json b/src/blocks/counter/block.json
index 84f2446e8c8..147343374a6 100644
--- a/src/blocks/counter/block.json
+++ b/src/blocks/counter/block.json
@@ -1,6 +1,6 @@
{
- "$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
+ "$schema": "https://schemas.wp.org/trunk/block.json",
"name": "coblocks/counter",
"title": "Counter",
"category": "widgets",
@@ -44,7 +44,5 @@
}
}
},
- "editorStyle": "wp-block-coblocks-counter-editor",
- "editorScript": "blocks-13",
- "style": "wp-block-coblocks-counter"
-}
\ No newline at end of file
+ "editorScript": ["coblocks-13"]
+}
diff --git a/src/blocks/dynamic-separator/block.json b/src/blocks/dynamic-separator/block.json
index bdcea52301a..d945db143eb 100644
--- a/src/blocks/dynamic-separator/block.json
+++ b/src/blocks/dynamic-separator/block.json
@@ -15,6 +15,6 @@
},
"title": "Dynamic Separator",
"textdomain": "coblocks",
- "editorScript": "blocks-2",
+ "editorScript": ["coblocks-2"],
"description": "Add a resizable spacer between other blocks."
}
diff --git a/src/blocks/events/block.json b/src/blocks/events/block.json
index 33a4550e39d..608a94f71f3 100644
--- a/src/blocks/events/block.json
+++ b/src/blocks/events/block.json
@@ -30,6 +30,7 @@
},
"title": "Events",
"textdomain": "coblocks",
- "editorScript": "blocks-2",
- "description": "Add a list of events or display events from a public calendar."
+ "description": "Add a list of events or display events from a public calendar.",
+ "editorScript": ["coblocks-2"],
+ "render": "index.php"
}
diff --git a/src/blocks/events/event-item/block.json b/src/blocks/events/event-item/block.json
index aa6a2216094..12502c1bea2 100644
--- a/src/blocks/events/event-item/block.json
+++ b/src/blocks/events/event-item/block.json
@@ -46,7 +46,7 @@
},
"title": "Event Item",
"textdomain": "coblocks",
- "editorScript": "blocks-2",
"description": "An event within the events block.",
+ "editorScript": ["coblocks-2"],
"parent": [ "coblocks/events" ]
}
diff --git a/src/blocks/events/index.php b/src/blocks/events/index.php
index a324a178e35..eadd227637b 100644
--- a/src/blocks/events/index.php
+++ b/src/blocks/events/index.php
@@ -13,7 +13,7 @@
*
* @return string Returns the events content.
*/
-function coblocks_render_events_block( $attributes, $content ) {
+function coblocks_render_coblocks_events_block( $attributes, $content ) {
if ( empty( $attributes['externalCalendarUrl'] ) ) {
return $content;
@@ -171,8 +171,8 @@ function coblocks_render_events_block( $attributes, $content ) {
$events_layout .= ' ';
- $events_layout .= ' ';
- $events_layout .= ' ';
+ $events_layout .= sprintf( ' ', __( 'Previous post', 'coblocks' ) );
+ $events_layout .= sprintf( ' ', __( 'Next post', 'coblocks' ) );
$events_layout .= ' ';
@@ -266,29 +266,3 @@ function coblocks_render_multi_day_event_item( $start_date, $end_date, ...$event
function coblocks_render_single_day_event_item( ...$event_data ) {
return coblocks_render_event_item( ...$event_data );
}
-
-/**
- * Registers the `events` block on server.
- */
-function coblocks_register_events_block() {
-
- // Return early if this function does not exist.
- if ( ! function_exists( 'register_block_type' ) ) {
- return;
- }
-
- // Load attributes from block.json.
- ob_start();
- include COBLOCKS_PLUGIN_DIR . 'src/blocks/events/block.json';
- $metadata = json_decode( ob_get_clean(), true );
-
- register_block_type(
- 'coblocks/events',
- array(
- 'attributes' => $metadata['attributes'],
- 'render_callback' => 'coblocks_render_events_block',
- )
- );
-}
-
-add_action( 'init', 'coblocks_register_events_block' );
diff --git a/src/blocks/faq/block.json b/src/blocks/faq/block.json
index 1412b7e6239..ede600ea3db 100644
--- a/src/blocks/faq/block.json
+++ b/src/blocks/faq/block.json
@@ -11,6 +11,6 @@
},
"title": "FAQ",
"textdomain": "coblocks",
- "editorScript": "blocks-2",
+ "editorScript": ["coblocks-2"],
"description": "Add a list of questions and answers."
}
diff --git a/src/blocks/faq/faq-item/block.json b/src/blocks/faq/faq-item/block.json
index 0acf63faa9c..76d1613af9a 100644
--- a/src/blocks/faq/faq-item/block.json
+++ b/src/blocks/faq/faq-item/block.json
@@ -14,7 +14,7 @@
},
"title": "FAQ Item",
"textdomain": "coblocks",
- "editorScript": "blocks-2",
"description": "A question/answer within the FAQ block.",
+ "editorScript": ["coblocks-2"],
"parent": [ "coblocks/faq" ]
}
diff --git a/src/blocks/features/block.json b/src/blocks/features/block.json
index fe0f792ca07..b31538606c3 100644
--- a/src/blocks/features/block.json
+++ b/src/blocks/features/block.json
@@ -17,6 +17,6 @@
},
"title": "Features",
"textdomain": "coblocks",
- "editorScript": "blocks-2",
+ "editorScript": ["coblocks-2"],
"description": "Add up to four columns of small notes for your product or service."
}
diff --git a/src/blocks/features/feature/block.json b/src/blocks/features/feature/block.json
index 5ae0a8f4956..ddd6c4cab62 100644
--- a/src/blocks/features/feature/block.json
+++ b/src/blocks/features/feature/block.json
@@ -18,7 +18,7 @@
},
"title": "Feature",
"textdomain": "coblocks",
- "editorScript": "blocks-2",
"description": "A singular child column within a parent features block.",
+ "editorScript": ["coblocks-2"],
"parent": [ "coblocks/features" ]
}
diff --git a/src/blocks/food-and-drinks/block.json b/src/blocks/food-and-drinks/block.json
index e7fe0d0fa2a..d822c4dfa56 100644
--- a/src/blocks/food-and-drinks/block.json
+++ b/src/blocks/food-and-drinks/block.json
@@ -25,6 +25,6 @@
},
"title": "Food & Drink",
"textdomain": "coblocks",
- "editorScript": "blocks-4",
+ "editorScript": ["coblocks-4"],
"description": "Display a menu or price list."
}
diff --git a/src/blocks/food-and-drinks/food-item/block.json b/src/blocks/food-and-drinks/food-item/block.json
index cfd452934f5..30ac978d3a6 100644
--- a/src/blocks/food-and-drinks/food-item/block.json
+++ b/src/blocks/food-and-drinks/food-item/block.json
@@ -73,7 +73,7 @@
},
"title": "Food Item",
"textdomain": "coblocks",
- "editorScript": "blocks-4",
"description": "A food and drink item within the Food & Drinks block.",
+ "editorScript": ["coblocks-4"],
"parent": [ "coblocks/food-and-drinks" ]
}
diff --git a/src/blocks/food-and-drinks/food-item/test/deprecated.spec.js b/src/blocks/food-and-drinks/food-item/test/deprecated.spec.js
index 4bd2e50ade0..d34fcdfe91a 100644
--- a/src/blocks/food-and-drinks/food-item/test/deprecated.spec.js
+++ b/src/blocks/food-and-drinks/food-item/test/deprecated.spec.js
@@ -25,6 +25,7 @@ const variations = {
showImage: [ undefined, true, false ],
showPrice: [ undefined, true, false ],
headingLevel: [ 2, 3, 4 ],
+ className: [ undefined, '', 'className' ],
};
helpers.testDeprecatedBlockVariations( name, settings, variations );
diff --git a/src/blocks/food-and-drinks/test/food-and-drinks.cypress.js b/src/blocks/food-and-drinks/test/food-and-drinks.cypress.js
index 58bc69a010a..8897ca7b133 100644
--- a/src/blocks/food-and-drinks/test/food-and-drinks.cypress.js
+++ b/src/blocks/food-and-drinks/test/food-and-drinks.cypress.js
@@ -10,9 +10,10 @@ describe( 'Block: Food and Drinks', function() {
*/
it( 'can be inserted without errors', function() {
helpers.addBlockToPost( 'coblocks/food-and-drinks', true );
- helpers.selectBlock( 'food & drink' );
+ helpers.selectBlock( 'Food & Drink' );
cy.get( '.wp-block-coblocks-food-and-drinks' ).should( 'exist' );
+
helpers.checkForBlockErrors( 'coblocks/food-and-drinks' );
} );
@@ -21,8 +22,8 @@ describe( 'Block: Food and Drinks', function() {
*/
it( 'can set custom classes', () => {
helpers.addBlockToPost( 'coblocks/food-and-drinks', false ); // Was failing when true here
- helpers.selectBlock( 'food & drink' );
+ helpers.selectBlock( 'Food & Drink' );
helpers.addCustomBlockClass( 'my-custom-class', 'food-and-drinks' );
cy.get( '.wp-block-coblocks-food-and-drinks' ).should( 'have.class', 'my-custom-class' );
@@ -31,10 +32,9 @@ describe( 'Block: Food and Drinks', function() {
it( 'can set the number of columns between 2 and 4', () => {
helpers.addBlockToPost( 'coblocks/food-and-drinks', true );
- helpers.selectBlock( 'food & drink' );
+ helpers.selectBlock( 'Food & Drink' );
helpers.setBlockStyle( 'grid' );
-
helpers.openSettingsPanel( /food & drinks settings/i );
[ 2, 3, 4 ].forEach( ( columns ) => {
@@ -49,10 +49,9 @@ describe( 'Block: Food and Drinks', function() {
it( 'can set the gutter to small, medium, large, and huge', () => {
helpers.addBlockToPost( 'coblocks/food-and-drinks', true );
- helpers.selectBlock( 'food & drink' );
+ helpers.selectBlock( 'Food & Drink' );
helpers.setBlockStyle( 'grid' );
-
helpers.openSettingsPanel( /food & drinks settings/i );
[ 'Small', 'Medium', 'Large', 'Huge' ].forEach( ( gutter ) => {
@@ -65,13 +64,15 @@ describe( 'Block: Food and Drinks', function() {
it( 'can toggle images for inner food-item blocks', () => {
helpers.addBlockToPost( 'coblocks/food-and-drinks', true );
- helpers.selectBlock( 'food & drink' );
cy.get( '[data-type="coblocks/food-and-drinks"]' ).first().within( () => {
cy.get( '[data-type="coblocks/food-item"]' ).first().click( 'left' );
cy.get( '[data-type="coblocks/food-item"]' ).first().find( '.block-editor-media-placeholder' ).should( 'not.exist' );
} );
+ // An unknown condition is causing the food-and-drinks block to become unselected.
+ // Two select block logics are needed to get the block to be selected.
+ helpers.selectBlock( 'Food & Drink' );
helpers.selectBlock( 'Food & Drink' );
helpers.openSettingsPanel( /food & drinks settings/i );
@@ -89,15 +90,16 @@ describe( 'Block: Food and Drinks', function() {
it( 'can toggle prices for inner food-item blocks', () => {
helpers.addBlockToPost( 'coblocks/food-and-drinks', true );
- helpers.selectBlock( 'food & drink' );
cy.get( '[data-type="coblocks/food-and-drinks"]' ).first().within( () => {
cy.get( '[data-type="coblocks/food-item"]' ).first().click( 'left' );
cy.get( '[data-type="coblocks/food-item"]' ).first().find( '[aria-label="$0.00"]' ).should( 'exist' );
} );
+ // An unknown condition is causing the block to become unselected only in headless.
+ // Two select block logics are needed to get the block to be selected.
+ helpers.selectBlock( 'Food & Drink' );
helpers.selectBlock( 'Food & Drink' );
-
helpers.openSettingsPanel( /food & drinks settings/i );
cy.get( '.components-toggle-control' ).find( '.components-base-control__field' ).contains( /prices/i ).click();
@@ -115,13 +117,9 @@ describe( 'Block: Food and Drinks', function() {
* Test the food-and-drinks block saves with custom classes
*/
it( 'Test the food-and-drinks block custom classes.', function() {
- helpers.addBlockToPost( 'coblocks/food-and-drinks', true );
- helpers.selectBlock( 'food & drink' );
-
helpers.addBlockToPost( 'coblocks/food-and-drinks', true );
- helpers.selectBlock( 'food & drink' );
-
+ helpers.selectBlock( 'Food & Drink' );
helpers.openSettingsPanel( /food & drinks settings/i );
cy.get( '.components-toggle-control' ).find( '.components-base-control__field' ).contains( /prices/i ).click();
@@ -137,8 +135,8 @@ describe( 'Block: Food and Drinks', function() {
it( 'can insert menu section with the same attributes', () => {
helpers.addBlockToPost( 'coblocks/food-and-drinks', true );
- helpers.selectBlock( 'food & drink' );
+ helpers.selectBlock( 'Food & Drink' );
helpers.openSettingsPanel( /food & drinks settings/i );
// Set a couple attributes.
@@ -168,12 +166,12 @@ describe( 'Block: Food and Drinks', function() {
*/
it( 'Updates the inner blocks when the "Heading Level" control is changed.', function() {
helpers.addBlockToPost( 'coblocks/food-and-drinks', true );
- helpers.selectBlock( 'food & drink' );
// Assert headings levels are set to default (h4)
cy.get( '[data-type="coblocks/food-and-drinks"] [data-type="coblocks/food-item"] h4' ).should( 'have.length', 2 );
// Modify the heading level
+ helpers.selectBlock( 'Food & Drink' );
cy.get( '.block-editor-block-toolbar [aria-label="Change heading level"]' ).click();
cy.get( 'div[aria-label="Change heading level"][role="menu"] button' ).contains( 'Heading 2' ).click();
diff --git a/src/blocks/form/block.json b/src/blocks/form/block.json
index 715c8cd8e81..d4c17fb0d2f 100644
--- a/src/blocks/form/block.json
+++ b/src/blocks/form/block.json
@@ -17,6 +17,19 @@
"name": "coblocks/form",
"title": "Form",
"textdomain": "coblocks",
- "editorScript": "blocks-4",
- "description": "Add a contact form to your page."
-}
\ No newline at end of file
+ "description": "Add a contact form to your page.",
+ "render": "index.php",
+ "editorScript": ["coblocks-3"],
+ "keywords": ["about", "contact", "email"],
+ "supports": {
+ "customClassName": false,
+ "html": false,
+ "labelColor": true,
+ "reusable": false
+ },
+ "example": {
+ "attributes": {
+ "subject": "Subject example"
+ }
+ }
+}
diff --git a/src/blocks/form/fields/checkbox/block.json b/src/blocks/form/fields/field-checkbox/block.json
similarity index 89%
rename from src/blocks/form/fields/checkbox/block.json
rename to src/blocks/form/fields/field-checkbox/block.json
index 29aeb033fdc..b385f0095b8 100644
--- a/src/blocks/form/fields/checkbox/block.json
+++ b/src/blocks/form/fields/field-checkbox/block.json
@@ -21,9 +21,10 @@
"category": "layout",
"title": "Checkbox",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A checkbox field with multiple options where multiple choices can be made.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/checkbox/index.js b/src/blocks/form/fields/field-checkbox/index.js
similarity index 100%
rename from src/blocks/form/fields/checkbox/index.js
rename to src/blocks/form/fields/field-checkbox/index.js
diff --git a/src/blocks/form/fields/checkbox/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-checkbox/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/checkbox/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-checkbox/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/checkbox/test/save.spec.js b/src/blocks/form/fields/field-checkbox/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/checkbox/test/save.spec.js
rename to src/blocks/form/fields/field-checkbox/test/save.spec.js
diff --git a/src/blocks/form/fields/checkbox/test/transforms.spec.js b/src/blocks/form/fields/field-checkbox/test/transforms.spec.js
similarity index 100%
rename from src/blocks/form/fields/checkbox/test/transforms.spec.js
rename to src/blocks/form/fields/field-checkbox/test/transforms.spec.js
diff --git a/src/blocks/form/fields/checkbox/transforms.js b/src/blocks/form/fields/field-checkbox/transforms.js
similarity index 100%
rename from src/blocks/form/fields/checkbox/transforms.js
rename to src/blocks/form/fields/field-checkbox/transforms.js
diff --git a/src/blocks/form/fields/date/block.json b/src/blocks/form/fields/field-date/block.json
similarity index 85%
rename from src/blocks/form/fields/date/block.json
rename to src/blocks/form/fields/field-date/block.json
index 678baeb2664..873b12b808e 100644
--- a/src/blocks/form/fields/date/block.json
+++ b/src/blocks/form/fields/field-date/block.json
@@ -13,9 +13,10 @@
},
"title": "Date",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A field for requesting date selections with a date picker.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/date/edit.js b/src/blocks/form/fields/field-date/edit.js
similarity index 100%
rename from src/blocks/form/fields/date/edit.js
rename to src/blocks/form/fields/field-date/edit.js
diff --git a/src/blocks/form/fields/date/index.js b/src/blocks/form/fields/field-date/index.js
similarity index 100%
rename from src/blocks/form/fields/date/index.js
rename to src/blocks/form/fields/field-date/index.js
diff --git a/src/blocks/form/fields/date/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-date/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/date/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-date/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/date/test/save.spec.js b/src/blocks/form/fields/field-date/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/date/test/save.spec.js
rename to src/blocks/form/fields/field-date/test/save.spec.js
diff --git a/src/blocks/form/fields/date/test/transforms.spec.js b/src/blocks/form/fields/field-date/test/transforms.spec.js
similarity index 100%
rename from src/blocks/form/fields/date/test/transforms.spec.js
rename to src/blocks/form/fields/field-date/test/transforms.spec.js
diff --git a/src/blocks/form/fields/date/transforms.js b/src/blocks/form/fields/field-date/transforms.js
similarity index 100%
rename from src/blocks/form/fields/date/transforms.js
rename to src/blocks/form/fields/field-date/transforms.js
diff --git a/src/blocks/form/fields/email/block.json b/src/blocks/form/fields/field-email/block.json
similarity index 84%
rename from src/blocks/form/fields/email/block.json
rename to src/blocks/form/fields/field-email/block.json
index cc69d18f5d2..0461ea1516f 100644
--- a/src/blocks/form/fields/email/block.json
+++ b/src/blocks/form/fields/field-email/block.json
@@ -13,9 +13,10 @@
},
"title": "Email",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A field for collecting a validated email address.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/email/edit.js b/src/blocks/form/fields/field-email/edit.js
similarity index 100%
rename from src/blocks/form/fields/email/edit.js
rename to src/blocks/form/fields/field-email/edit.js
diff --git a/src/blocks/form/fields/email/index.js b/src/blocks/form/fields/field-email/index.js
similarity index 100%
rename from src/blocks/form/fields/email/index.js
rename to src/blocks/form/fields/field-email/index.js
diff --git a/src/blocks/form/fields/email/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-email/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/email/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-email/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/email/test/save.spec.js b/src/blocks/form/fields/field-email/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/email/test/save.spec.js
rename to src/blocks/form/fields/field-email/test/save.spec.js
diff --git a/src/blocks/form/fields/hidden/block.json b/src/blocks/form/fields/field-hidden/block.json
similarity index 84%
rename from src/blocks/form/fields/hidden/block.json
rename to src/blocks/form/fields/field-hidden/block.json
index 2ad02f33695..9d580323bba 100644
--- a/src/blocks/form/fields/hidden/block.json
+++ b/src/blocks/form/fields/field-hidden/block.json
@@ -13,9 +13,10 @@
},
"title": "Hidden",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A hidden text field for collecting additional data.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/hidden/edit.js b/src/blocks/form/fields/field-hidden/edit.js
similarity index 100%
rename from src/blocks/form/fields/hidden/edit.js
rename to src/blocks/form/fields/field-hidden/edit.js
diff --git a/src/blocks/form/fields/hidden/index.js b/src/blocks/form/fields/field-hidden/index.js
similarity index 100%
rename from src/blocks/form/fields/hidden/index.js
rename to src/blocks/form/fields/field-hidden/index.js
diff --git a/src/blocks/form/fields/hidden/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-hidden/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/hidden/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-hidden/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/hidden/test/save.spec.js b/src/blocks/form/fields/field-hidden/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/hidden/test/save.spec.js
rename to src/blocks/form/fields/field-hidden/test/save.spec.js
diff --git a/src/blocks/form/fields/hidden/test/transforms.spec.js b/src/blocks/form/fields/field-hidden/test/transforms.spec.js
similarity index 100%
rename from src/blocks/form/fields/hidden/test/transforms.spec.js
rename to src/blocks/form/fields/field-hidden/test/transforms.spec.js
diff --git a/src/blocks/form/fields/hidden/transforms.js b/src/blocks/form/fields/field-hidden/transforms.js
similarity index 100%
rename from src/blocks/form/fields/hidden/transforms.js
rename to src/blocks/form/fields/field-hidden/transforms.js
diff --git a/src/blocks/form/fields/name/block.json b/src/blocks/form/fields/field-name/block.json
similarity index 89%
rename from src/blocks/form/fields/name/block.json
rename to src/blocks/form/fields/field-name/block.json
index 0839e70b8c6..0edd119bc44 100644
--- a/src/blocks/form/fields/name/block.json
+++ b/src/blocks/form/fields/field-name/block.json
@@ -25,9 +25,10 @@
},
"title": "Name",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A text field for collecting the first and last names.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/name/edit.js b/src/blocks/form/fields/field-name/edit.js
similarity index 100%
rename from src/blocks/form/fields/name/edit.js
rename to src/blocks/form/fields/field-name/edit.js
diff --git a/src/blocks/form/fields/name/index.js b/src/blocks/form/fields/field-name/index.js
similarity index 100%
rename from src/blocks/form/fields/name/index.js
rename to src/blocks/form/fields/field-name/index.js
diff --git a/src/blocks/form/fields/name/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-name/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/name/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-name/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/name/test/save.spec.js b/src/blocks/form/fields/field-name/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/name/test/save.spec.js
rename to src/blocks/form/fields/field-name/test/save.spec.js
diff --git a/src/blocks/form/fields/name/test/transforms.spec.js b/src/blocks/form/fields/field-name/test/transforms.spec.js
similarity index 100%
rename from src/blocks/form/fields/name/test/transforms.spec.js
rename to src/blocks/form/fields/field-name/test/transforms.spec.js
diff --git a/src/blocks/form/fields/name/transforms.js b/src/blocks/form/fields/field-name/transforms.js
similarity index 100%
rename from src/blocks/form/fields/name/transforms.js
rename to src/blocks/form/fields/field-name/transforms.js
diff --git a/src/blocks/form/fields/phone/block.json b/src/blocks/form/fields/field-phone/block.json
similarity index 84%
rename from src/blocks/form/fields/phone/block.json
rename to src/blocks/form/fields/field-phone/block.json
index c82d3f66dc4..c4fe56ac42b 100644
--- a/src/blocks/form/fields/phone/block.json
+++ b/src/blocks/form/fields/field-phone/block.json
@@ -13,9 +13,10 @@
},
"title": "Phone",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A text field for collecting a phone number.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/phone/edit.js b/src/blocks/form/fields/field-phone/edit.js
similarity index 100%
rename from src/blocks/form/fields/phone/edit.js
rename to src/blocks/form/fields/field-phone/edit.js
diff --git a/src/blocks/form/fields/phone/index.js b/src/blocks/form/fields/field-phone/index.js
similarity index 100%
rename from src/blocks/form/fields/phone/index.js
rename to src/blocks/form/fields/field-phone/index.js
diff --git a/src/blocks/form/fields/phone/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-phone/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/phone/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-phone/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/phone/test/save.spec.js b/src/blocks/form/fields/field-phone/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/phone/test/save.spec.js
rename to src/blocks/form/fields/field-phone/test/save.spec.js
diff --git a/src/blocks/form/fields/phone/test/transforms.spec.js b/src/blocks/form/fields/field-phone/test/transforms.spec.js
similarity index 100%
rename from src/blocks/form/fields/phone/test/transforms.spec.js
rename to src/blocks/form/fields/field-phone/test/transforms.spec.js
diff --git a/src/blocks/form/fields/phone/transforms.js b/src/blocks/form/fields/field-phone/transforms.js
similarity index 100%
rename from src/blocks/form/fields/phone/transforms.js
rename to src/blocks/form/fields/field-phone/transforms.js
diff --git a/src/blocks/form/fields/radio/block.json b/src/blocks/form/fields/field-radio/block.json
similarity index 88%
rename from src/blocks/form/fields/radio/block.json
rename to src/blocks/form/fields/field-radio/block.json
index aa68fea7c98..406ebee5f29 100644
--- a/src/blocks/form/fields/radio/block.json
+++ b/src/blocks/form/fields/field-radio/block.json
@@ -21,9 +21,10 @@
},
"title": "Radio",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A field with multiple options where only one choice can be made.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/radio/index.js b/src/blocks/form/fields/field-radio/index.js
similarity index 100%
rename from src/blocks/form/fields/radio/index.js
rename to src/blocks/form/fields/field-radio/index.js
diff --git a/src/blocks/form/fields/radio/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-radio/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/radio/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-radio/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/radio/test/save.spec.js b/src/blocks/form/fields/field-radio/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/radio/test/save.spec.js
rename to src/blocks/form/fields/field-radio/test/save.spec.js
diff --git a/src/blocks/form/fields/radio/test/transforms.spec.js b/src/blocks/form/fields/field-radio/test/transforms.spec.js
similarity index 100%
rename from src/blocks/form/fields/radio/test/transforms.spec.js
rename to src/blocks/form/fields/field-radio/test/transforms.spec.js
diff --git a/src/blocks/form/fields/radio/transforms.js b/src/blocks/form/fields/field-radio/transforms.js
similarity index 100%
rename from src/blocks/form/fields/radio/transforms.js
rename to src/blocks/form/fields/field-radio/transforms.js
diff --git a/src/blocks/form/fields/select/block.json b/src/blocks/form/fields/field-select/block.json
similarity index 87%
rename from src/blocks/form/fields/select/block.json
rename to src/blocks/form/fields/field-select/block.json
index 7303b155a05..3861b2eb8c3 100644
--- a/src/blocks/form/fields/select/block.json
+++ b/src/blocks/form/fields/field-select/block.json
@@ -17,9 +17,10 @@
},
"title": "Select",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A dropdown field with multiple options where only one choice can be made.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/select/index.js b/src/blocks/form/fields/field-select/index.js
similarity index 100%
rename from src/blocks/form/fields/select/index.js
rename to src/blocks/form/fields/field-select/index.js
diff --git a/src/blocks/form/fields/select/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-select/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/select/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-select/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/select/test/save.spec.js b/src/blocks/form/fields/field-select/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/select/test/save.spec.js
rename to src/blocks/form/fields/field-select/test/save.spec.js
diff --git a/src/blocks/form/fields/select/test/transforms.spec.js b/src/blocks/form/fields/field-select/test/transforms.spec.js
similarity index 100%
rename from src/blocks/form/fields/select/test/transforms.spec.js
rename to src/blocks/form/fields/field-select/test/transforms.spec.js
diff --git a/src/blocks/form/fields/select/transforms.js b/src/blocks/form/fields/field-select/transforms.js
similarity index 100%
rename from src/blocks/form/fields/select/transforms.js
rename to src/blocks/form/fields/field-select/transforms.js
diff --git a/src/blocks/form/fields/submit-button/block.json b/src/blocks/form/fields/field-submit-button/block.json
similarity index 89%
rename from src/blocks/form/fields/submit-button/block.json
rename to src/blocks/form/fields/field-submit-button/block.json
index a24601cfa2b..db13b7058f4 100644
--- a/src/blocks/form/fields/submit-button/block.json
+++ b/src/blocks/form/fields/field-submit-button/block.json
@@ -23,9 +23,10 @@
},
"title": "Submit",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A button for submitting form data.",
"parent": [
"coblocks/form"
- ]
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
}
diff --git a/src/blocks/form/fields/submit-button/edit.js b/src/blocks/form/fields/field-submit-button/edit.js
similarity index 100%
rename from src/blocks/form/fields/submit-button/edit.js
rename to src/blocks/form/fields/field-submit-button/edit.js
diff --git a/src/blocks/form/fields/submit-button/index.js b/src/blocks/form/fields/field-submit-button/index.js
similarity index 100%
rename from src/blocks/form/fields/submit-button/index.js
rename to src/blocks/form/fields/field-submit-button/index.js
diff --git a/src/blocks/form/fields/submit-button/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-submit-button/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/submit-button/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-submit-button/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/submit-button/test/save.spec.js b/src/blocks/form/fields/field-submit-button/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/submit-button/test/save.spec.js
rename to src/blocks/form/fields/field-submit-button/test/save.spec.js
diff --git a/src/blocks/form/fields/text/block.json b/src/blocks/form/fields/field-text/block.json
similarity index 84%
rename from src/blocks/form/fields/text/block.json
rename to src/blocks/form/fields/field-text/block.json
index 36d4030949a..73b10946502 100644
--- a/src/blocks/form/fields/text/block.json
+++ b/src/blocks/form/fields/field-text/block.json
@@ -13,9 +13,10 @@
},
"title": "Text",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A text box for custom responses.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/text/edit.js b/src/blocks/form/fields/field-text/edit.js
similarity index 100%
rename from src/blocks/form/fields/text/edit.js
rename to src/blocks/form/fields/field-text/edit.js
diff --git a/src/blocks/form/fields/text/index.js b/src/blocks/form/fields/field-text/index.js
similarity index 100%
rename from src/blocks/form/fields/text/index.js
rename to src/blocks/form/fields/field-text/index.js
diff --git a/src/blocks/form/fields/text/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-text/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/text/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-text/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/text/test/save.spec.js b/src/blocks/form/fields/field-text/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/text/test/save.spec.js
rename to src/blocks/form/fields/field-text/test/save.spec.js
diff --git a/src/blocks/form/fields/text/test/transforms.spec.js b/src/blocks/form/fields/field-text/test/transforms.spec.js
similarity index 100%
rename from src/blocks/form/fields/text/test/transforms.spec.js
rename to src/blocks/form/fields/field-text/test/transforms.spec.js
diff --git a/src/blocks/form/fields/text/transforms.js b/src/blocks/form/fields/field-text/transforms.js
similarity index 100%
rename from src/blocks/form/fields/text/transforms.js
rename to src/blocks/form/fields/field-text/transforms.js
diff --git a/src/blocks/form/fields/textarea/block.json b/src/blocks/form/fields/field-textarea/block.json
similarity index 84%
rename from src/blocks/form/fields/textarea/block.json
rename to src/blocks/form/fields/field-textarea/block.json
index 96d50607484..02665c0fce3 100644
--- a/src/blocks/form/fields/textarea/block.json
+++ b/src/blocks/form/fields/field-textarea/block.json
@@ -13,9 +13,10 @@
},
"title": "Textarea",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A text box for longer responses.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/textarea/edit.js b/src/blocks/form/fields/field-textarea/edit.js
similarity index 100%
rename from src/blocks/form/fields/textarea/edit.js
rename to src/blocks/form/fields/field-textarea/edit.js
diff --git a/src/blocks/form/fields/textarea/index.js b/src/blocks/form/fields/field-textarea/index.js
similarity index 100%
rename from src/blocks/form/fields/textarea/index.js
rename to src/blocks/form/fields/field-textarea/index.js
diff --git a/src/blocks/form/fields/textarea/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-textarea/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/textarea/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-textarea/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/textarea/test/save.spec.js b/src/blocks/form/fields/field-textarea/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/textarea/test/save.spec.js
rename to src/blocks/form/fields/field-textarea/test/save.spec.js
diff --git a/src/blocks/form/fields/textarea/test/transforms.spec.js b/src/blocks/form/fields/field-textarea/test/transforms.spec.js
similarity index 100%
rename from src/blocks/form/fields/textarea/test/transforms.spec.js
rename to src/blocks/form/fields/field-textarea/test/transforms.spec.js
diff --git a/src/blocks/form/fields/textarea/transforms.js b/src/blocks/form/fields/field-textarea/transforms.js
similarity index 100%
rename from src/blocks/form/fields/textarea/transforms.js
rename to src/blocks/form/fields/field-textarea/transforms.js
diff --git a/src/blocks/form/fields/website/block.json b/src/blocks/form/fields/field-website/block.json
similarity index 84%
rename from src/blocks/form/fields/website/block.json
rename to src/blocks/form/fields/field-website/block.json
index 7065883c99d..d8922ba98e7 100644
--- a/src/blocks/form/fields/website/block.json
+++ b/src/blocks/form/fields/field-website/block.json
@@ -13,9 +13,10 @@
},
"title": "Website",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
"description": "A text field for collecting a URL.",
"parent": [
"coblocks/form"
- ]
-}
\ No newline at end of file
+ ],
+ "editorScript": ["coblocks-3"],
+ "render": "index.php"
+}
diff --git a/src/blocks/form/fields/website/edit.js b/src/blocks/form/fields/field-website/edit.js
similarity index 100%
rename from src/blocks/form/fields/website/edit.js
rename to src/blocks/form/fields/field-website/edit.js
diff --git a/src/blocks/form/fields/website/index.js b/src/blocks/form/fields/field-website/index.js
similarity index 100%
rename from src/blocks/form/fields/website/index.js
rename to src/blocks/form/fields/field-website/index.js
diff --git a/src/blocks/form/fields/website/test/__snapshots__/save.spec.js.snap b/src/blocks/form/fields/field-website/test/__snapshots__/save.spec.js.snap
similarity index 100%
rename from src/blocks/form/fields/website/test/__snapshots__/save.spec.js.snap
rename to src/blocks/form/fields/field-website/test/__snapshots__/save.spec.js.snap
diff --git a/src/blocks/form/fields/website/test/save.spec.js b/src/blocks/form/fields/field-website/test/save.spec.js
similarity index 100%
rename from src/blocks/form/fields/website/test/save.spec.js
rename to src/blocks/form/fields/field-website/test/save.spec.js
diff --git a/src/blocks/form/fields/website/test/transforms.spec.js b/src/blocks/form/fields/field-website/test/transforms.spec.js
similarity index 100%
rename from src/blocks/form/fields/website/test/transforms.spec.js
rename to src/blocks/form/fields/field-website/test/transforms.spec.js
diff --git a/src/blocks/form/fields/website/transforms.js b/src/blocks/form/fields/field-website/transforms.js
similarity index 100%
rename from src/blocks/form/fields/website/transforms.js
rename to src/blocks/form/fields/field-website/transforms.js
diff --git a/src/blocks/form/index.js b/src/blocks/form/index.js
index 7be3a447eb0..373234bebe9 100644
--- a/src/blocks/form/index.js
+++ b/src/blocks/form/index.js
@@ -15,7 +15,6 @@ import variations from './variations';
/**
* WordPress dependencies
*/
-import { __ } from '@wordpress/i18n';
import { Icon } from '@wordpress/components';
import { InnerBlocks } from '@wordpress/block-editor';
@@ -41,33 +40,9 @@ if ( typeof coblocksBlockData !== 'undefined' ) {
const settings = {
attributes: conditionalBlockAttributes,
- /* translators: block description */
- description: __( 'Add a contact form to your page.', 'coblocks' ),
edit,
- example: {
- attributes: {
- subject: __( 'Subject example', 'coblocks' ),
- },
- },
icon:
,
- keywords: [
- 'coblocks',
- /* translators: block keyword */
- __( 'email', 'coblocks' ),
- /* translators: block keyword */
- __( 'about', 'coblocks' ),
- /* translators: block keyword */
- __( 'contact', 'coblocks' ),
- ],
save: InnerBlocks.Content,
- supports: {
- customClassName: false,
- html: false,
- labelColor: true,
- reusable: false,
- },
- /* translators: block name */
- title: __( 'Form', 'coblocks' ),
variations,
};
diff --git a/src/blocks/form/test/save.spec.js b/src/blocks/form/test/save.spec.js
index 847822b3c96..57cb2f21d35 100644
--- a/src/blocks/form/test/save.spec.js
+++ b/src/blocks/form/test/save.spec.js
@@ -7,7 +7,7 @@ import { registerBlockType, createBlock, serialize } from '@wordpress/blocks';
/**
* Internal dependencies.
*/
-import { name, settings } from '../index';
+import { name, settings, metadata } from '../index';
// Make variables accessible for all tests.
let block;
@@ -16,7 +16,7 @@ let serializedBlock;
describe( 'coblocks/form', () => {
beforeAll( () => {
// Register the block.
- registerBlockType( name, { category: 'common', ...settings } );
+ registerBlockType( metadata, { category: 'common', ...settings } );
} );
beforeEach( () => {
diff --git a/src/blocks/gallery-carousel/block.json b/src/blocks/gallery-carousel/block.json
index 0ba8415ce82..9d10833e4c6 100644
--- a/src/blocks/gallery-carousel/block.json
+++ b/src/blocks/gallery-carousel/block.json
@@ -1,4 +1,5 @@
{
+ "$schema": "https://schemas.wp.org/trunk/block.json",
"name": "coblocks/gallery-carousel",
"category": "media",
"attributes": {
@@ -109,6 +110,12 @@
},
"title": "Carousel",
"textdomain": "coblocks",
- "editorScript": "blocks-1",
- "description": "Display multiple images in a beautiful carousel gallery."
+ "editorScript": ["coblocks-1"],
+ "script": [ "coblocks-tiny-swiper", "coblocks-tinyswiper-initializer" ],
+ "description": "Display multiple images in a beautiful carousel gallery.",
+ "supports": {
+ "align": [ "wide", "full" ],
+ "html": false,
+ "coBlocksSpacing": true
+ }
}
diff --git a/src/blocks/gallery-carousel/gallery-carousel-item.js b/src/blocks/gallery-carousel/gallery-carousel-item.js
index b8f858fce67..6a49683c0ae 100644
--- a/src/blocks/gallery-carousel/gallery-carousel-item.js
+++ b/src/blocks/gallery-carousel/gallery-carousel-item.js
@@ -108,13 +108,13 @@ const GalleryCarouselItem = ( {
return (
{ renderGalleryItem }
{ isItemSelected ? renderCaption : null }
diff --git a/src/blocks/gallery-collage/block.json b/src/blocks/gallery-collage/block.json
index 1cacc939547..dba76091f32 100644
--- a/src/blocks/gallery-collage/block.json
+++ b/src/blocks/gallery-collage/block.json
@@ -55,8 +55,15 @@
"default": "wide"
}
},
+ "supports": {
+ "align": [ "wide", "full" ],
+ "gutter": {
+ "default": "small",
+ "customDefault": 0.2
+ }
+ },
"title": "Collage",
"textdomain": "coblocks",
- "editorScript": "blocks-3",
+ "editorScript": ["coblocks-4"],
"description": "Assemble images into a beautiful collage gallery."
}
diff --git a/src/blocks/gallery-collage/deprecated.js b/src/blocks/gallery-collage/deprecated.js
index d2c5b789068..68444887790 100644
--- a/src/blocks/gallery-collage/deprecated.js
+++ b/src/blocks/gallery-collage/deprecated.js
@@ -168,12 +168,12 @@ const deprecated =
...GalleryAttributes,
...metadata.attributes,
gutter: {
- default: 'small',
- type: 'string',
+ default: 1,
+ type: 'number',
},
gutterCustom: {
- default: '3',
- type: 'string',
+ default: 3,
+ type: 'number',
},
images: {
...metadata.attributes.images,
@@ -259,12 +259,12 @@ const deprecated =
...metadata.attributes,
gutter: {
- default: 'small',
- type: 'string',
+ default: 1,
+ type: 'number',
},
gutterCustom: {
- default: '3',
- type: 'string',
+ default: 3,
+ type: 'number',
},
images: {
...metadata.attributes.images,
@@ -362,8 +362,12 @@ const deprecated =
...GalleryAttributes,
...metadata.attributes,
gutter: {
- default: 'small',
- type: 'string',
+ default: 1,
+ type: 'number',
+ },
+ gutterCustom: {
+ default: 3,
+ type: 'number',
},
},
save: ( { attributes } ) => {
diff --git a/src/blocks/gallery-collage/index.js b/src/blocks/gallery-collage/index.js
index 836842262b8..e8aa658780a 100644
--- a/src/blocks/gallery-collage/index.js
+++ b/src/blocks/gallery-collage/index.js
@@ -36,10 +36,6 @@ const attributes = {
};
const settings = {
- /* translators: block name */
- title: __( 'Collage', 'coblocks' ),
- /* translators: block description */
- description: __( 'Assemble images into a beautiful collage gallery.', 'coblocks' ),
category: hasFormattingCategory ? 'coblocks-galleries' : 'media',
icon: ,
keywords: [
@@ -67,12 +63,6 @@ const settings = {
label: __( 'Layered', 'coblocks' ),
},
],
- supports: {
- align: [ 'wide', 'full' ],
- gutter: {
- default: 'small',
- },
- },
example: {
attributes: {
images: [
diff --git a/src/blocks/gallery-collage/test/deprecated.spec.js b/src/blocks/gallery-collage/test/deprecated.spec.js
new file mode 100644
index 00000000000..77185c19e16
--- /dev/null
+++ b/src/blocks/gallery-collage/test/deprecated.spec.js
@@ -0,0 +1,52 @@
+/**
+ * Internal dependencies.
+ */
+import * as helpers from '../../../../.dev/tests/jest/helpers';
+import { name, settings, metadata } from '../index';
+
+const variations = {
+ images: [
+ [],
+ [ { url: 'https://wordpress.com/wp-content/uploads/1234/56/image-1.jpg', id: 1, href: 'https://wordpress.com/wp-content/uploads/1234/56/image-1.jpg', caption: 'image-1 caption' } ],
+ ],
+ linkTo: [ undefined, 'none', 'media', 'attachment', 'custom' ],
+ target: [ '', '_blank', '_self', '_parent' ],
+ rel: [ '', 'alternate', 'author', 'preload' ],
+ align: [ '', 'wide', 'full', 'left', 'center', 'right' ],
+ gutter: [ 0, 10, 100, ],
+ gutterCustom: [ 0, 10, 100 ],
+ gutterMobile: [ 0, 10, 100 ],
+ radius: [ undefined, 0, 20 ],
+ shadow: [ undefined, 'none', 'sml', 'med', 'lrg', 'xlrg' ],
+ filter: [ 'none', 'grayscale', 'sepia', 'saturation', 'dim', 'vintage' ],
+ captions: [ undefined, true, false ],
+ captionStyle: [ 'none', 'dark', 'light' ],
+ captionColor: [ undefined, 'primary' ],
+ customCaptionColor: [ undefined, '#123456' ],
+ fontSize: [ undefined, 'small', 'large' ],
+ customFontSize: [ undefined, 0, 16, '0', '16' ],
+ primaryCaption: [ undefined, '', 'caption text' ],
+ backgroundRadius: [ undefined, 0, 20 ],
+ backgroundPadding: [ undefined, 'none', 'small', 'medium', 'large', 'xlarge' ],
+ backgroundPaddingMobile: [ undefined, 'none', 'small', 'medium', 'large', 'xlarge' ],
+ lightbox: [ undefined, true, false ],
+ backgroundType: [ undefined, '', 'image', 'video' ],
+ backgroundImg: [ undefined, '', 'https://website.com/wp-content/uploads/1234/56/image.jpg', 'https://website.com/wp-content/uploads/1234/56/video.mp4' ],
+ backgroundPosition: [ undefined, '' ],
+ backgroundRepeat: [ 'no-repeat', 'repeat', 'repeat-x', 'repeat-y' ],
+ backgroundSize: [ 'cover', 'contain' ],
+ backgroundOverlay: [ 0, 100 ],
+ backgroundColor: [ undefined, 'primary' ],
+ customBackgroundColor: [ '#123456' ],
+ hasParallax: [ undefined, true, false ],
+ focalPoint: [ undefined, { x: 0, y: 0 }, { x: 0.33663366336633666, y: 0.8335193452380952 } ],
+ videoMuted: [ undefined, true, false ],
+ videoLoop: [ undefined, true, false ],
+ openPopover: [ undefined, true, false ],
+ gridSize: [ 'none', 'sml', 'med', 'lrg', 'xlrg' ],
+ className: [ undefined, '', 'random classes' ],
+ noBottomMargin: [ undefined, true, false ],
+ noTopMargin: [ undefined, true, false ],
+};
+
+helpers.testDeprecatedBlockVariations( name, {...metadata, ...settings}, variations );
diff --git a/src/blocks/gallery-collage/test/save.spec.js b/src/blocks/gallery-collage/test/save.spec.js
index ec2f1a04337..38e1518f14a 100644
--- a/src/blocks/gallery-collage/test/save.spec.js
+++ b/src/blocks/gallery-collage/test/save.spec.js
@@ -2,12 +2,13 @@
* External dependencies
*/
import '@testing-library/jest-dom/extend-expect';
-import { createBlock, registerBlockType, serialize } from '@wordpress/blocks';
+import { createBlock, serialize } from '@wordpress/blocks';
/**
* Internal dependencies.
*/
-import { name, settings } from '../index';
+import * as settings from '../index';
+import { registerBlock } from '../../../../src/utils/helper';
// Make variables accessible for all tests.
let block;
@@ -19,11 +20,12 @@ const baseAttributes = {
{ url: 'https://wordpress.com/wp-content/uploads/1234/56/image-2.jpg', id: 2, index: 1 },
],
};
+const name = settings?.metadata?.name ?? settings?.name;
describe( 'coblocks/gallery-collage', () => {
beforeAll( () => {
// Register the block.
- registerBlockType( name, { category: 'common', ...settings } );
+ registerBlock( settings );
} );
beforeEach( () => {
diff --git a/src/blocks/gallery-masonry/block.json b/src/blocks/gallery-masonry/block.json
index 0f583dab993..be040aab0d0 100644
--- a/src/blocks/gallery-masonry/block.json
+++ b/src/blocks/gallery-masonry/block.json
@@ -1,13 +1,14 @@
{
- "$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
+ "$schema": "https://schemas.wp.org/trunk/block.json",
"name": "coblocks/gallery-masonry",
"title": "Masonry Gallery",
"category": "media",
"description": "Display multiple images in a masonry style gallery.",
"keywords": [
"images",
- "photos"
+ "photos",
+ "lightbox"
],
"textdomain": "coblocks",
"attributes": {
@@ -78,10 +79,38 @@
"default": false
}
},
+ "example": {
+ "innerBlocks": [
+ {
+ "attributes": { "url": "https://s.w.org/images/core/5.3/Sediment_off_the_Yucatan_Peninsula.jpg" },
+ "name": "core/image"
+ },
+ {
+ "attributes": { "url": "https://s.w.org/images/core/5.3/Windbuchencom.jpg" },
+ "name": "core/image"
+
+ },
+ {
+ "attributes": { "url": "https://s.w.org/images/core/5.3/Biologia_Centrali-Americana_-_Cantorchilus_semibadius_1902.jpg" },
+ "name": "core/image"
+
+ },
+ {
+ "attributes": { "url": "https://s.w.org/images/core/5.3/MtBlanc1.jpg" },
+ "name": "core/image"
+
+ },
+ {
+ "attributes": { "url": "https://s.w.org/images/core/5.3/Glacial_lakes,_Bhutan.jpg" },
+ "name": "core/image"
+ }
+ ]
+ },
"providesContext": {
"allowResize": "allowResize",
"imageCrop": "imageCrop"
},
+ "editorScript": ["coblocks-5"],
"supports": {
"anchor": true,
"gutter": {
@@ -94,8 +123,5 @@
],
"coBlocksSpacing": true,
"html": false
- },
- "editorStyle": "wp-block-coblocks-gallery-masonry-editor",
- "style": "wp-block-coblocks-gallery-masonry",
- "editorScript": "blocks-5"
-}
\ No newline at end of file
+ }
+}
diff --git a/src/blocks/gallery-masonry/index.js b/src/blocks/gallery-masonry/index.js
index 0c82f9e1ff9..3c3697d86bf 100644
--- a/src/blocks/gallery-masonry/index.js
+++ b/src/blocks/gallery-masonry/index.js
@@ -6,7 +6,6 @@ import { GalleryMasonryIcon as icon } from '@godaddy-wordpress/coblocks-icons';
/**
* WordPress dependencies
*/
-import { __ } from '@wordpress/i18n';
import { Icon, Spinner } from '@wordpress/components';
import { lazy, Suspense } from '@wordpress/element';
@@ -35,53 +34,13 @@ const settings = {
attributes,
category: hasFormattingCategory ? 'coblocks-galleries' : 'media',
deprecated,
- /* translators: block description */
- description: __( 'Display multiple images in an organized masonry gallery.', 'coblocks' ),
edit: ( props ) => (
}>
),
- example: {
- innerBlocks: [
- {
- attributes: { url: 'https://s.w.org/images/core/5.3/Sediment_off_the_Yucatan_Peninsula.jpg' },
- name: 'core/image',
- },
- {
- attributes: { url: 'https://s.w.org/images/core/5.3/Windbuchencom.jpg' },
- name: 'core/image',
-
- },
- {
- attributes: { url: 'https://s.w.org/images/core/5.3/Biologia_Centrali-Americana_-_Cantorchilus_semibadius_1902.jpg' },
- name: 'core/image',
-
- },
- {
- attributes: { url: 'https://s.w.org/images/core/5.3/MtBlanc1.jpg' },
- name: 'core/image',
-
- },
- {
- attributes: { url: 'hhttps://s.w.org/images/core/5.3/Glacial_lakes,_Bhutan.jpg' },
- name: 'core/image',
- },
- ],
- },
icon: ,
- keywords: [
- 'coblocks',
- /* translators: block keyword */
- __( 'gallery', 'coblocks' ),
- /* translators: block keyword */
- __( 'photos', 'coblocks' ),
- /* translators: block keyword */
- __( 'lightbox', 'coblocks' ),
- ],
save,
- /* translators: block name */
- title: __( 'Masonry', 'coblocks' ),
transforms,
};
diff --git a/src/blocks/gallery-masonry/test/deprecated.spec.js b/src/blocks/gallery-masonry/test/deprecated.spec.js
index b71132f0ca1..d51b212b353 100644
--- a/src/blocks/gallery-masonry/test/deprecated.spec.js
+++ b/src/blocks/gallery-masonry/test/deprecated.spec.js
@@ -2,7 +2,7 @@
* Internal dependencies.
*/
import * as helpers from '../../../../.dev/tests/jest/helpers';
-import { name, settings } from '../index';
+import { name, settings, metadata } from '../index';
const variations = {
images: [
@@ -13,6 +13,7 @@ const variations = {
target: [ '', '_blank', '_self', '_parent' ],
rel: [ '', 'alternate', 'author', 'preload' ],
align: [ '', 'wide', 'full', 'left', 'center', 'right' ],
+ anchor: [ undefined, 'anchor' ],
gutter: [ 0, 10, 100 ],
gutterMobile: [ 0, 10, 100 ],
radius: [ undefined, 0, 20 ],
@@ -48,4 +49,4 @@ const variations = {
noTopMargin: [ undefined, true, false ],
};
-helpers.testDeprecatedBlockVariations( name, settings, variations );
+helpers.testDeprecatedBlockVariations( name, {...metadata, ...settings}, variations );
diff --git a/src/blocks/gallery-masonry/test/gallery-masonry.cypress.js b/src/blocks/gallery-masonry/test/gallery-masonry.cypress.js
index 77ea8bf8ce5..2897f375726 100644
--- a/src/blocks/gallery-masonry/test/gallery-masonry.cypress.js
+++ b/src/blocks/gallery-masonry/test/gallery-masonry.cypress.js
@@ -31,7 +31,7 @@ describe( 'Test CoBlocks Gallery Masonry Block', function() {
const { imageBase } = helpers.upload.spec;
helpers.addBlockToPost( 'coblocks/gallery-masonry', true );
- cy.get( '[data-type="coblocks/gallery-masonry"]' ).click();
+ cy.get( 'figure[data-type="coblocks/gallery-masonry"]' ).click();
helpers.upload.imageToBlock( 'coblocks/gallery-masonry' );
@@ -49,7 +49,7 @@ describe( 'Test CoBlocks Gallery Masonry Block', function() {
it( 'Test masonry block saves with images from media library.', function() {
helpers.addBlockToPost( 'coblocks/gallery-masonry', true );
- cy.get( '[data-type="coblocks/gallery-masonry"]' )
+ cy.get( 'figure[data-type="coblocks/gallery-masonry"]' )
.click()
.contains( /media library/i )
.click();
@@ -76,7 +76,7 @@ describe( 'Test CoBlocks Gallery Masonry Block', function() {
const { caption } = galleryData;
helpers.addBlockToPost( 'coblocks/gallery-masonry', true );
- cy.get( '[data-type="coblocks/gallery-masonry"]' )
+ cy.get( 'figure[data-type="coblocks/gallery-masonry"]' )
.click()
.contains( /media library/i )
.click();
@@ -91,7 +91,7 @@ describe( 'Test CoBlocks Gallery Masonry Block', function() {
cy.get( 'button' ).contains( /insert gallery/i ).click();
if ( helpers.isWP62AtLeast() ) {
- helpers.selectBlock( 'masonry gallery' );
+ helpers.selectBlock( 'masonry' );
cy.get( 'figcaption[role="textbox"]' ).click( { force: true } );
@@ -115,7 +115,7 @@ describe( 'Test CoBlocks Gallery Masonry Block', function() {
it( 'Test masonry captions allow rich text controls.', function() {
helpers.addBlockToPost( 'coblocks/gallery-masonry', true );
- cy.get( '[data-type="coblocks/gallery-masonry"]' )
+ cy.get( 'figure' )
.click()
.contains( /media library/i )
.click();
@@ -130,7 +130,7 @@ describe( 'Test CoBlocks Gallery Masonry Block', function() {
cy.get( 'button' ).contains( /insert gallery/i ).click();
if ( helpers.isWP62AtLeast() ) {
- helpers.selectBlock( 'masonry gallery' );
+ helpers.selectBlock( 'masonry' );
cy.get( '.block-editor-format-toolbar' ).should( 'not.exist' );
@@ -156,7 +156,7 @@ describe( 'Test CoBlocks Gallery Masonry Block', function() {
it( 'Test masonry replace image flow.', function() {
helpers.addBlockToPost( 'coblocks/gallery-masonry', true );
- cy.get( '[data-type="coblocks/gallery-masonry"]' )
+ cy.get( 'figure[data-type="coblocks/gallery-masonry"]' )
.click()
.contains( /media library/i )
.click();
@@ -170,19 +170,19 @@ describe( 'Test CoBlocks Gallery Masonry Block', function() {
cy.get( 'button' ).contains( /create a new gallery/i ).click();
cy.get( 'button' ).contains( /insert gallery/i ).click();
- helpers.selectBlock( 'image', true );
+ helpers.selectBlock( 'image' );
//'.media-replace-flow button' was deprecated in 5.8.
// Media replace button should reside as the 5th button within the toolbar.
- cy.get( '.block-editor-block-toolbar div:nth-of-type(4) button' ).contains( 'Replace' ).click();
+ cy.get( '.block-editor-block-toolbar div:nth-of-type(4) button:not(.has-icon)' ).click();
cy.get( '.components-popover__content' ).should( 'be.visible' );
cy.get( '.block-editor-media-replace-flow__media-upload-menu .components-menu-item__button' ).contains( 'Open Media Library' );
- cy.get( '.block-editor-block-toolbar div:nth-of-type(4) button' ).contains( 'Replace' ).click();
+ cy.get( '.block-editor-block-toolbar div:nth-of-type(4) button:not(.has-icon)' ).click();
- cy.get( '[data-type="coblocks/gallery-masonry"]' ).click();
+ cy.get( 'figure[data-type="coblocks/gallery-masonry"]' ).click();
cy.get( '.components-popover__content' ).should( 'not.exist' );
diff --git a/src/blocks/gallery-masonry/test/save.spec.js b/src/blocks/gallery-masonry/test/save.spec.js
index e326bcb62a5..8558fcd364e 100644
--- a/src/blocks/gallery-masonry/test/save.spec.js
+++ b/src/blocks/gallery-masonry/test/save.spec.js
@@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { registerCoreBlocks } from '@wordpress/block-library';
-import { createBlock, registerBlockType, serialize } from '@wordpress/blocks';
+import { createBlock, serialize } from '@wordpress/blocks';
registerCoreBlocks();
@@ -14,7 +14,8 @@ import '@testing-library/jest-dom/extend-expect';
/**
* Internal dependencies.
*/
-import { name, settings } from '../index';
+import * as settings from '../index';
+import { registerBlock } from '../../../../src/utils/helper';
// Make variables accessible for all tests.
let block;
@@ -40,12 +41,12 @@ const baseInnerBlocks = [
describe( 'coblocks/gallery-masonry', () => {
beforeAll( () => {
// Register the block.
- registerBlockType( name, { category: 'common', ...settings } );
+ registerBlock( settings );
} );
beforeEach( () => {
// Create the block with the minimum attributes.
- block = createBlock( name, baseAttributes, baseInnerBlocks );
+ block = createBlock( settings.name, baseAttributes, baseInnerBlocks );
// Reset the reused variables.
serializedBlock = '';
} );
diff --git a/src/blocks/gallery-offset/block.json b/src/blocks/gallery-offset/block.json
index dcb45c37503..54a5bea1ae2 100644
--- a/src/blocks/gallery-offset/block.json
+++ b/src/blocks/gallery-offset/block.json
@@ -9,6 +9,6 @@
},
"title": "Offset",
"textdomain": "coblocks",
- "editorScript": "blocks-7",
+ "editorScript": ["coblocks-7"],
"description": "Display images in an offset brick pattern gallery."
}
diff --git a/src/blocks/gallery-offset/index.js b/src/blocks/gallery-offset/index.js
index 4a51c613a6a..9c0896c2aa3 100644
--- a/src/blocks/gallery-offset/index.js
+++ b/src/blocks/gallery-offset/index.js
@@ -35,10 +35,6 @@ const attributes = {
};
const settings = {
- /* translators: block name */
- title: __( 'Offset', 'coblocks' ),
- /* translators: block description */
- description: __( 'Display images in an offset brick pattern gallery.', 'coblocks' ),
category: hasFormattingCategory ? 'coblocks-galleries' : 'media',
icon: ,
keywords: [
diff --git a/src/blocks/gallery-offset/test/deprecated.spec.js b/src/blocks/gallery-offset/test/deprecated.spec.js
new file mode 100644
index 00000000000..c1bf6c9f8cc
--- /dev/null
+++ b/src/blocks/gallery-offset/test/deprecated.spec.js
@@ -0,0 +1,51 @@
+/**
+ * Internal dependencies.
+ */
+import * as helpers from '../../../../.dev/tests/jest/helpers';
+import { name, settings, metadata } from '../index';
+
+const variations = {
+ images: [
+ [],
+ [ { url: 'https://wordpress.com/wp-content/uploads/1234/56/image-1.jpg', id: 1, href: 'https://wordpress.com/wp-content/uploads/1234/56/image-1.jpg', caption: 'image-1 caption' } ],
+ ],
+ linkTo: [ undefined, 'none', 'media', 'attachment', 'custom' ],
+ target: [ '', '_blank', '_self', '_parent' ],
+ rel: [ '', 'alternate', 'author', 'preload' ],
+ align: [ undefined, 'wide', 'full' ],
+ gutter: [ 0, 10, 100 ],
+ gutterMobile: [ 0, 10, 100 ],
+ radius: [ undefined, 0, 20 ],
+ shadow: [ undefined, 'none', 'sml', 'med', 'lrg', 'xlrg' ],
+ filter: [ 'none', 'grayscale', 'sepia', 'saturation', 'dim', 'vintage' ],
+ captions: [ undefined, true, false ],
+ captionStyle: [ 'none', 'dark', 'light' ],
+ captionColor: [ undefined, 'primary' ],
+ customCaptionColor: [ undefined, '#123456' ],
+ fontSize: [ undefined, 'small', 'large' ],
+ customFontSize: [ undefined, 0, 16, '0', '16' ],
+ primaryCaption: [ undefined, '', 'caption text' ],
+ backgroundRadius: [ undefined, 0, 20 ],
+ backgroundPadding: [ undefined, 'none', 'small', 'medium', 'large', 'xlarge' ],
+ backgroundPaddingMobile: [ undefined, 'none', 'small', 'medium', 'large', 'xlarge' ],
+ lightbox: [ undefined, true, false ],
+ backgroundType: [ undefined, '', 'image', 'video' ],
+ backgroundImg: [ undefined, '', 'https://website.com/wp-content/uploads/1234/56/image.jpg', 'https://website.com/wp-content/uploads/1234/56/video.mp4' ],
+ backgroundPosition: [ undefined, '' ],
+ backgroundRepeat: [ 'no-repeat', 'repeat', 'repeat-x', 'repeat-y' ],
+ backgroundSize: [ 'cover', 'contain' ],
+ backgroundOverlay: [ 0, 100 ],
+ backgroundColor: [ undefined, 'primary' ],
+ customBackgroundColor: [ '#123456' ],
+ hasParallax: [ undefined, true, false ],
+ focalPoint: [ undefined, { x: 0, y: 0 }, { x: 0.33663366336633666, y: 0.8335193452380952 } ],
+ videoMuted: [ undefined, true, false ],
+ videoLoop: [ undefined, true, false ],
+ openPopover: [ undefined, true, false ],
+ gridSize: [ 'none', 'sml', 'med', 'lrg', 'xlrg' ],
+ className: [ undefined, '', 'random classes' ],
+ noBottomMargin: [ undefined, true, false ],
+ noTopMargin: [ undefined, true, false ],
+};
+
+helpers.testDeprecatedBlockVariations( name, {...metadata, ...settings}, variations );
diff --git a/src/blocks/gallery-offset/test/save.spec.js b/src/blocks/gallery-offset/test/save.spec.js
index 3652735f963..1bab16a98f3 100644
--- a/src/blocks/gallery-offset/test/save.spec.js
+++ b/src/blocks/gallery-offset/test/save.spec.js
@@ -2,12 +2,13 @@
* External dependencies
*/
import '@testing-library/jest-dom/extend-expect';
-import { createBlock, registerBlockType, serialize } from '@wordpress/blocks';
+import { createBlock, serialize } from '@wordpress/blocks';
/**
* Internal dependencies.
*/
-import { name, settings } from '../index';
+import * as settings from '../index';
+import { registerBlock } from '../../../../src/utils/helper';
// Make variables accessible for all tests.
let block;
@@ -21,10 +22,11 @@ const baseAttributes = {
],
};
+const name = settings?.metadata?.name ?? settings?.name;
describe( 'coblocks/gallery-offset', () => {
beforeAll( () => {
// Register the block.
- registerBlockType( name, { category: 'common', ...settings } );
+ registerBlock( settings );
} );
beforeEach( () => {
diff --git a/src/blocks/gallery-stacked/block.json b/src/blocks/gallery-stacked/block.json
index 1f0da58b8cd..fa470c6e3f6 100644
--- a/src/blocks/gallery-stacked/block.json
+++ b/src/blocks/gallery-stacked/block.json
@@ -1,6 +1,6 @@
{
- "$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
+ "$schema": "https://schemas.wp.org/trunk/block.json",
"name": "coblocks/gallery-stacked",
"category": "media",
"attributes": {
@@ -92,6 +92,6 @@
},
"textdomain": "coblocks",
"title": "Stacked",
- "editorScript": "blocks-10",
+ "editorScript": ["coblocks-10"],
"description": "Display multiple images in a single column stacked gallery."
-}
\ No newline at end of file
+}
diff --git a/src/blocks/gif/block.json b/src/blocks/gif/block.json
index 18305dcdb99..79b3a0ecbb3 100644
--- a/src/blocks/gif/block.json
+++ b/src/blocks/gif/block.json
@@ -32,6 +32,6 @@
},
"title": "Gif",
"textdomain": "coblocks",
- "editorScript": "blocks-9",
+ "editorScript": ["coblocks-9"],
"description": "Pick a gif, any gif."
}
diff --git a/src/blocks/gist/block.json b/src/blocks/gist/block.json
index 829dc20b245..bf6fac2fd5f 100644
--- a/src/blocks/gist/block.json
+++ b/src/blocks/gist/block.json
@@ -18,6 +18,6 @@
},
"title": "Gist",
"textdomain": "coblocks",
- "editorScript": "blocks-9",
+ "editorScript": ["coblocks-9"],
"description": "Embed a GitHub Gist."
}
diff --git a/src/blocks/hero/block.json b/src/blocks/hero/block.json
index 91a44ce5f75..d501a5e6cad 100644
--- a/src/blocks/hero/block.json
+++ b/src/blocks/hero/block.json
@@ -57,6 +57,6 @@
},
"title": "Hero",
"textdomain": "coblocks",
- "editorScript": "blocks-9",
+ "editorScript": ["coblocks-9"],
"description": "An introductory area of a page accompanied by a small amount of text and a call to action."
}
diff --git a/src/blocks/hero/test/hero.cypress.js b/src/blocks/hero/test/hero.cypress.js
index f81451c7e8d..1b593faf6fe 100644
--- a/src/blocks/hero/test/hero.cypress.js
+++ b/src/blocks/hero/test/hero.cypress.js
@@ -42,8 +42,8 @@ describe( 'Test CoBlocks Hero Block', function() {
helpers.selectBlock( 'hero' );
- cy.get( '[data-type="core/heading"]' ).focus().type( 'Heading Text' );
- cy.get( '[data-type="core/paragraph"]' ).first().focus().type( 'Paragraph Text' );
+ cy.get( '[data-type="core/heading"]' ).focus().type( 'Heading Text', { force: true } );
+ cy.get( '[data-type="core/paragraph"]' ).first().focus().type( 'Paragraph Text', { force: true } );
cy.get( '.wp-block-coblocks-hero' ).click( { force: true } );
@@ -106,8 +106,9 @@ describe( 'Test CoBlocks Hero Block', function() {
cy.get( '.attachment.selected.save-ready' );
cy.get( '.media-toolbar-primary > .button' ).click();
- // Media replace button should reside as the 6th button within the toolbar.
- cy.get( '.block-editor-block-toolbar button:nth(5)' ).click();
+ // Media replace button is the only one without an aria-label.
+ // Added aria-label to the SVG icon manually.
+ cy.get( '.block-editor-block-toolbar svg[aria-label="Replace background image"]' ).click();
cy.get( '.components-popover__content' ).should( 'be.visible' );
diff --git a/src/blocks/highlight/block.json b/src/blocks/highlight/block.json
index 7a6dcbd4112..3c692825aef 100644
--- a/src/blocks/highlight/block.json
+++ b/src/blocks/highlight/block.json
@@ -1,6 +1,6 @@
{
- "$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
+ "$schema": "https://schemas.wp.org/trunk/block.json",
"name": "coblocks/highlight",
"category": "formatting",
"attributes": {
@@ -32,6 +32,6 @@
},
"textdomain": "coblocks",
"title": "Highlight",
- "editorScript": "blocks-9",
+ "editorScript": ["coblocks-9"],
"description": "Draw attention and emphasize important narrative."
-}
\ No newline at end of file
+}
diff --git a/src/blocks/icon/block.json b/src/blocks/icon/block.json
index 6c76d6677a2..5d0634651d3 100644
--- a/src/blocks/icon/block.json
+++ b/src/blocks/icon/block.json
@@ -57,6 +57,7 @@
},
"title": "Icon",
"textdomain": "coblocks",
- "editorScript": "blocks-8",
- "description": "Add a stylized graphic symbol to communicate something more."
+ "description": "Add a stylized graphic symbol to communicate something more.",
+ "editorScript": ["coblocks-8"],
+ "render": "index.php"
}
diff --git a/src/blocks/icon/index.php b/src/blocks/icon/index.php
index ccb58b6ff80..f1636be093c 100644
--- a/src/blocks/icon/index.php
+++ b/src/blocks/icon/index.php
@@ -12,7 +12,7 @@
*
* @return string Returns the block content.
*/
-function coblocks_render_icon_block( $attrs ) {
+function coblocks_render_coblocks_icon_block( $attrs ) {
if ( ! is_array( $attrs ) ) {
$attrs = array();
}
@@ -112,20 +112,3 @@ function coblocks_render_icon_block( $attrs ) {
)
);
}
-
-/**
- * Registers the block on server.
- */
-function coblocks_register_icon_block() {
- if ( ! function_exists( 'register_block_type' ) ) {
- return;
- }
-
- register_block_type(
- COBLOCKS_PLUGIN_DIR . 'src/blocks/icon',
- array(
- 'render_callback' => 'coblocks_render_icon_block',
- )
- );
-}
-add_action( 'init', 'coblocks_register_icon_block' );
diff --git a/src/blocks/logos/block.json b/src/blocks/logos/block.json
index e381aacb0cc..88fecb78b13 100644
--- a/src/blocks/logos/block.json
+++ b/src/blocks/logos/block.json
@@ -37,6 +37,6 @@
},
"title": "Logos",
"textdomain": "coblocks",
- "editorScript": "blocks-5",
+ "editorScript": ["coblocks-5"],
"description": "Add logos, badges, or certifications to build credibility."
}
diff --git a/src/blocks/map/block.json b/src/blocks/map/block.json
index b95af46df7d..e5de12141c4 100644
--- a/src/blocks/map/block.json
+++ b/src/blocks/map/block.json
@@ -61,6 +61,6 @@
},
"title": "Map",
"textdomain": "coblocks",
- "editorScript": "blocks-12",
+ "editorScript": ["coblocks-12"],
"description": "Add an address or location to drop a pin on a Google map."
}
diff --git a/src/blocks/media-card/block.json b/src/blocks/media-card/block.json
index 5af664b7877..cc23ef47170 100644
--- a/src/blocks/media-card/block.json
+++ b/src/blocks/media-card/block.json
@@ -47,6 +47,6 @@
},
"title": "Media Card",
"textdomain": "coblocks",
- "editorScript": "blocks-7",
+ "editorScript": ["coblocks-7"],
"description": "Add an image or video with an offset card side-by-side."
}
diff --git a/src/blocks/opentable/block.json b/src/blocks/opentable/block.json
index 34d1793e694..0bc04e9525f 100644
--- a/src/blocks/opentable/block.json
+++ b/src/blocks/opentable/block.json
@@ -13,6 +13,6 @@
},
"title": "OpenTable",
"textdomain": "coblocks",
- "editorScript": "blocks-7",
+ "editorScript": ["coblocks-7"],
"description": "Embed an OpenTable Reservations Widget."
}
diff --git a/src/blocks/post-carousel/block.json b/src/blocks/post-carousel/block.json
index ec1486061cd..de1e2a5ae2e 100644
--- a/src/blocks/post-carousel/block.json
+++ b/src/blocks/post-carousel/block.json
@@ -73,6 +73,7 @@
},
"title": "Post Carousel (CoBlocks)",
"textdomain": "coblocks",
- "editorScript": "blocks-11",
- "description": "Display posts or an external blog feed as a carousel."
+ "description": "Display posts or an external blog feed as a carousel.",
+ "editorScript": ["coblocks-11"],
+ "render": "index.php"
}
diff --git a/src/blocks/post-carousel/index.js b/src/blocks/post-carousel/index.js
index 9d0dec0e573..96d4e18e560 100755
--- a/src/blocks/post-carousel/index.js
+++ b/src/blocks/post-carousel/index.js
@@ -61,4 +61,4 @@ const settings = {
},
};
-export { name, category, settings };
+export { name, category, settings, metadata };
diff --git a/src/blocks/post-carousel/index.php b/src/blocks/post-carousel/index.php
index 51d43605820..dde7a4fdf6e 100755
--- a/src/blocks/post-carousel/index.php
+++ b/src/blocks/post-carousel/index.php
@@ -12,7 +12,7 @@
*
* @return string Returns the block content.
*/
-function coblocks_render_post_carousel_block( $attributes ) {
+function coblocks_render_coblocks_post_carousel_block( $attributes ) {
global $post;
@@ -233,8 +233,8 @@ function coblocks_post_carousel( $posts, $attributes ) {
$block_content .= '
';
$block_content .= '
';
- $block_content .= '