From 3cbe31434d64c8750436b97853ab9717d6579850 Mon Sep 17 00:00:00 2001 From: Daniel Waxweiler Date: Mon, 6 Jun 2022 14:58:45 +0200 Subject: [PATCH] move block properties to PHP as attribute default values are not known to backend otherwise --- source/front/blocks/events-list/edit.js | 2 +- source/front/blocks/events-list/index.js | 25 +----------------------- source/includes/events-list-block.php | 16 +++++++++++++++ 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/source/front/blocks/events-list/edit.js b/source/front/blocks/events-list/edit.js index 79662b0..ac70e5d 100644 --- a/source/front/blocks/events-list/edit.js +++ b/source/front/blocks/events-list/edit.js @@ -2,8 +2,8 @@ import { loadEventList } from '../../events-loader.js' const { InspectorControls, useBlockProps } = wp.blockEditor -const { useEffect } = wp.element const { PanelBody } = wp.components +const { useEffect } = wp.element const { __ } = wp.i18n const NAME = '' diff --git a/source/front/blocks/events-list/index.js b/source/front/blocks/events-list/index.js index 8d86533..7fb1373 100644 --- a/source/front/blocks/events-list/index.js +++ b/source/front/blocks/events-list/index.js @@ -1,30 +1,7 @@ import edit from './edit.js' const { registerBlockType } = wp.blocks -const { __ } = wp.i18n const NAME = '' -registerBlockType(NAME + '/events-list', { - apiVersion: 2, - title: __('Events List', ''), - description: __( - 'A list of the upcoming events of the connected Mobilizon instance.', - '' - ), - icon: 'list-view', - category: 'widgets', - attributes: { - eventsCount: { - type: 'number', - default: 3, - }, - groupName: { - type: 'string', - }, - }, - supports: { - html: false, - }, - edit, -}) +registerBlockType(NAME + '/events-list', { edit }) diff --git a/source/includes/events-list-block.php b/source/includes/events-list-block.php index 77b83c9..747d48c 100644 --- a/source/includes/events-list-block.php +++ b/source/includes/events-list-block.php @@ -19,6 +19,22 @@ class EventsListBlock { ]); register_block_type(NAME . '/events-list', [ 'api_version' => 2, + 'title' => __('Events List', 'connector-mobilizon'), + 'description' => __('A list of the upcoming events of the connected Mobilizon instance.', 'connector-mobilizon'), + 'category' => 'widgets', + 'icon' => 'list-view', + 'supports' => [ + 'html' => false + ], + 'attributes' => [ + 'eventsCount' => [ + 'type' => 'number', + 'default' => 3, + ], + 'groupName' => [ + 'type' => 'string', + ], + ], 'editor_script' => $scriptName, 'render_callback' => 'MobilizonConnector\EventsListBlock::render', ]);