move block properties to PHP as attribute default values are not known to backend otherwise

This commit is contained in:
Daniel Waxweiler 2022-06-06 14:58:45 +02:00
parent 54807da6fe
commit 3cbe31434d
3 changed files with 18 additions and 25 deletions

View File

@ -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 = '<wordpress-name>'

View File

@ -1,30 +1,7 @@
import edit from './edit.js'
const { registerBlockType } = wp.blocks
const { __ } = wp.i18n
const NAME = '<wordpress-name>'
registerBlockType(NAME + '/events-list', {
apiVersion: 2,
title: __('Events List', '<wordpress-name>'),
description: __(
'A list of the upcoming events of the connected Mobilizon instance.',
'<wordpress-name>'
),
icon: 'list-view',
category: 'widgets',
attributes: {
eventsCount: {
type: 'number',
default: 3,
},
groupName: {
type: 'string',
},
},
supports: {
html: false,
},
edit,
})
registerBlockType(NAME + '/events-list', { edit })

View File

@ -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',
]);