Skip to content

Commit

Permalink
changed blocks registration to register_block_type_from_metadata
Browse files Browse the repository at this point in the history
added support for new Ghost Kit extensions
  • Loading branch information
nk-o committed Nov 25, 2023
1 parent 66c14f2 commit 683e02e
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 68 deletions.
2 changes: 1 addition & 1 deletion build/gutenberg/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('jquery', 'lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'eeb006fa5c19f8e2d012');
<?php return array('dependencies' => array('jquery', 'lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '73ed561ca29115334e44');
2 changes: 1 addition & 1 deletion build/gutenberg/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/gutenberg/layouts-editor.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => '59d6f76362d56ef3e875');
<?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => 'cd65d6b5e7981b2c3805');
2 changes: 1 addition & 1 deletion build/gutenberg/layouts-editor.js

Large diffs are not rendered by default.

61 changes: 31 additions & 30 deletions classes/class-gutenberg-saved.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,59 +25,60 @@ class Visual_Portfolio_Gutenberg_Saved_Block {
*/
public function __construct() {
add_action( 'init', array( $this, 'register_block' ), 11 );
add_action( 'admin_init', array( $this, 'register_block_layouts_editor' ), 11 );
}

/**
* Register Block.
*/
public function register_block() {
if ( ! function_exists( 'register_block_type' ) ) {
if ( ! function_exists( 'register_block_type_from_metadata' ) ) {
return;
}

// Default attributes.
$attributes = array(
'id' => array(
'type' => 'string',
),
'align' => array(
'type' => 'string',
),
'className' => array(
'type' => 'string',
),
'anchor' => array(
'type' => 'string',
),
);

register_block_type(
register_block_type_from_metadata(
visual_portfolio()->plugin_path . 'gutenberg/block-saved',
array(
'render_callback' => array( $this, 'block_render' ),
'attributes' => $attributes,
)
);

if ( 'vp_lists' === get_post_type() ) {
register_block_type(
visual_portfolio()->plugin_path . 'gutenberg/layouts-editor/block',
array(
'attributes' => $attributes,
)
);
}

// Fallback.
register_block_type(
register_block_type_from_metadata(
'nk/visual-portfolio',
array(
'render_callback' => array( $this, 'block_render' ),
'attributes' => $attributes,
'attributes' => array(
'id' => array(
'type' => 'string',
),
'align' => array(
'type' => 'string',
),
'className' => array(
'type' => 'string',
),
'anchor' => array(
'type' => 'string',
),
),
)
);
}

/**
* Register Block for Layouts Editor.
*/
public function register_block_layouts_editor() {
global $pagenow;

if ( 'post.php' === $pagenow && isset( $_GET['post'] ) && 'vp_lists' === get_post_type( $_GET['post'] ) ) {
register_block_type_from_metadata(
visual_portfolio()->plugin_path . 'gutenberg/layouts-editor/block'
);
}
}

/**
* Block output
*
Expand Down
4 changes: 2 additions & 2 deletions classes/class-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ public function get_block_attributes() {
* Register Block.
*/
public function register_block() {
if ( ! function_exists( 'register_block_type' ) ) {
if ( ! function_exists( 'register_block_type_from_metadata' ) ) {
return;
}

$attributes = $this->get_block_attributes();

register_block_type(
register_block_type_from_metadata(
visual_portfolio()->plugin_path . 'gutenberg/block',
array(
'render_callback' => array( $this, 'block_render' ),
Expand Down
6 changes: 6 additions & 0 deletions gutenberg/block-saved/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
"description": "Display saved Visual Portfolio layouts.",
"keywords": ["saved", "portfolio", "vpf"],
"textdomain": "visual-portfolio",
"attributes": {
"id": {
"type": "string"
}
},
"supports": {
"ghostkit": true,
"anchor": true,
"className": true,
"html": false,
Expand Down
7 changes: 0 additions & 7 deletions gutenberg/block-saved/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ export default [
type: 'string',
},
},
ghostkit: {
supports: {
spacings: true,
display: true,
scrollReveal: true,
},
},
supports: {
anchor: true,
className: true,
Expand Down
14 changes: 3 additions & 11 deletions gutenberg/block-saved/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import edit from './edit';
import save from './save';
import transforms from './transforms';

const { name } = metadata;
const { name, title } = metadata;

const settings = {
...metadata,
icon: {
foreground: '#2540CC',
src: (
Expand Down Expand Up @@ -71,14 +70,6 @@ const settings = {
</svg>
),
},
ghostkit: {
supports: {
styles: true,
spacings: true,
display: true,
scrollReveal: true,
},
},
edit,
save,
transforms,
Expand All @@ -89,9 +80,10 @@ registerBlockType(name, settings);
// Fallback.
registerBlockType('nk/visual-portfolio', {
...settings,
title,
name: 'nk/visual-portfolio',
supports: {
...settings.supports,
...metadata.supports,
inserter: false,
},
deprecated,
Expand Down
1 change: 1 addition & 0 deletions gutenberg/block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"keywords": ["gallery", "images", "posts", "portfolio", "vpf"],
"textdomain": "visual-portfolio",
"supports": {
"ghostkit": true,
"anchor": true,
"className": true,
"html": false,
Expand Down
11 changes: 0 additions & 11 deletions gutenberg/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,13 @@ import save from './save';
import transforms from './transforms';
import variations from './variations';

const { attributes } = window.VPGutenbergVariables;
const { name } = metadata;

const settings = {
...metadata,
attributes,
icon: {
foreground: '#2540CC',
src: <ElementIcon width="20" height="20" />,
},
ghostkit: {
supports: {
styles: true,
spacings: true,
display: true,
scrollReveal: true,
},
},
example: {
attributes: {
preview_image_example: 'true',
Expand Down
3 changes: 0 additions & 3 deletions gutenberg/layouts-editor/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { useState } from '@wordpress/element';
import { applyFilters } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';

import metadata from './block.json';

const { navigator } = window;

let copiedTimeout;
Expand Down Expand Up @@ -186,7 +184,6 @@ function LayoutsEditorBlock(props) {
}

registerBlockType('visual-portfolio/saved-editor', {
...metadata,
icon: {
foreground: '#2540CC',
src: (
Expand Down

0 comments on commit 683e02e

Please sign in to comment.