• This repository has been archived on 10/Feb/2020
  • Stars
    star
    167
  • Rank 225,335 (Top 5 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created over 6 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Register fields for Gutenberg blocks with less repetitive code

Gutenberg Fields Middleware

Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.


IMPORTANT

The work on Gutenberg Fields Middleware had started during the initial development phase of Gutenberg before it was merged into core. Gutenberg has evolved a lot since then and with the introduction of InnerBlocks and block templates, Gutenberg Fields Middleware has become less useful because the core blocks can be used as fields for creating blocks using block templates. Therefore we have stopped the development of this project and would archive this repo.


Register fields for Gutenberg blocks with a simple, declarative API.

This project is in its early stages. Please open an issue with questions, feedback, suggestions, and bug reports.

Using | Available Fields

Using

Gutenberg fields middleware requires only two files dist/middleware.min.js and dist/middleware.min.css as dependency.

There are two ways of using fields middleware.

  1. As a Plugin: Install the Gutenberg Fields Middleware as a standalone WordPress plugin which will register a gutenberg-fields-middleware handle you can add as a dependency for your block script.
  2. Using JS and CSS files: Or you can use middleware.min.js and middleware.min.css and enqueue them as dependency for your block script. Be sure to use array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-date', 'wp-hooks' ) handles as your dependency when enqueing middleware js file.

Fields are now registered as attribute configuration details. Here's how you might register image, text, color and range fields:

wp.blocks.registerBlockType( 'example-namespace/example-block', {
	title: 'Example Block',
	category: 'common',
	attributes: {
		image: {
			type: 'object',
			field: {
				type: 'image',
			},
		},
		text: {
			type: 'string',
			field: {
				type: 'text',
				placeholder: 'Enter text..',
			},
		},
		color: {
			type: 'string',
			field: {
				type: 'color',
				placement: 'inspector',
			},
		},
		range: {
			type: 'string',
			field: {
				type: 'range',
				label: 'Columns',
				placement: 'inspector', // To show in sidebar.
			},
			default: 20,
		},
	},

	edit: function( props, middleware ) {
		return [
			middleware.inspectorControls, // Contains ALL inspector controls.
			middleware.fields.image,
			middleware.fields.text,
		];
	},

	save: function( props ) {}
});

Which will create a block like this

image

βœ”οΈ Fields can also be used in the same way when using register_block_type in PHP.

register_block_type( 'example-namespace/example-block', array(
	'attributes' => array(
		'image' => array(
			'type' => 'object',
			'field' => array(
				'type' => 'image',
				'buttonText' => 'Upload',
				'imagePlaceholder' => true,
				'removeButtonText' => 'Remove',
			),
		),
		'color' => array(
			'type' => 'string',
			'field' => array(
				'type' => 'color'
			)
		)
	),
	'render_callback' => 'example_callback',
) );

βœ”οΈ Gutenberg fields middleware is also available as npm package.

npm i gutenberg-fields-middleware

Available Fields

Gutenberg Fields Middleware supports the following field types and type configuration.

Returning field in edit method:

  • middleware.fields.arrtibuteKeyName for a single field when placement property is not defined.
  • middleware.blockControls for all block-control fields. ( where placement is block-control )
  • middleware.inspectorControls for all inspector fields. ( where placement is inspector )

Getting more control over fields:

There are two ways of getting a field, one is simply use middleware.fields.arrtibuteKeyName or middleware.getField( props, 'arrtibuteKeyName', config ) when you need more control over a field, here you can use all configuration options in config parameter given in the fields doc.

The same can be done for block controls and inspector controls as middleware.getBlockControls( props, fields ) and middleware.getInspectorControls( props, fields ) where fields can be defined as an array of fields.

See example usage of alignment-toolbar.

Example Usage:

  • See examples
    • You can set GUTENBERG_FIELDS_MIDDLEWARE_IS_DEV to true during development in wp-config.php which will also enable example blocks.
  • Check gutenberg-supplements plugin where we have created some actual blocks using middleware.

Does this interest you?

Join us at rtCamp, we specialize in providing high performance enterprise WordPress solutions

More Repositories

1

action-slack-notify

GitHub Action for sending a notification to a Slack channel
Go
1,062
star
2

wp-decoupled

Next.js app with WPGraphQL and WordPress at the backend.
JavaScript
266
star
3

nginx-helper

Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
PHP
228
star
4

VueTheme

WordPress theme using Rest API and Vue.js
CSS
220
star
5

rtMedia

rtMedia (formerly Buddypress Media) adds advanced multimedia functionality to WordPress, BuddyPress and bbPress
PHP
123
star
6

action-deploy-wordpress

GitHub Action for deploying a WordPress site using using PHP's Deployer.org
Shell
120
star
7

Frappe-Manager

A CLI tool based on Docker Compose to easily manage Frappe based projects.
Python
106
star
8

action-phpcs-code-review

Github Action to perform automated code review on pull requests
Shell
101
star
9

github-actions-library

Collection of Github Actions useful for WordPress Deployments
93
star
10

wp-partytown

Add partytown support to WordPress sites.
JavaScript
74
star
11

login-with-google

Minimal plugin which allows WordPress user to login with google.
PHP
57
star
12

learn

rtCamp assignment and issue tracker
52
star
13

rtpanel

WordPress Theme Framework
PHP
43
star
14

gitbook-plugin-edit-link

GitBook Plugin to add "Edit with Github (or Gitlab)" link on every page
JavaScript
42
star
15

wordpress-skeleton

A base repository structure for rtCamp's WordPress sites, pre-configured to use Github Actions
PHP
40
star
16

gutenberg-supplements

JavaScript
28
star
17

rtsocial

rtSocial is lightest wordpress plugin for facebook & twitter social sharing
PHP
26
star
18

theme-elementary

A starter theme that facilitates a quick headstart for developing new block-based themes along with a bunch of developer-friendly features.
JavaScript
26
star
19

wpveda-book

We now have our own training module which has all the lessons that covers the core topics on WordPress and the various steps involved in WordPress development. Check it out
Shell
25
star
20

blank-theme

Customized Blank theme based on Underscore and Foundation
PHP
25
star
21

gitbook-plugin-collapsible-menu

GitBook Plugin to change sidebar menu's to collapsible menu. For gitbook with many pages, navigating long menus can get irritating.
JavaScript
24
star
22

woocommerce-to-easydigitaldownloads

A script to migrate products, orders, payments and other stuff from WooCommerce to EasyDigitalDownloads
PHP
21
star
23

rt-optimizer

A WordPress plugin that improves Core Web Vitals score by loading scripts via worker thread. Keeps the main thread idle for users to interact with page as quickly as possible.
PHP
18
star
24

rtpanel-child-theme

Example child theme for rtPanel wordpress theme framework
CSS
16
star
25

rtbiz

WordPress 4 Business!
PHP
16
star
26

web-story-creation-tool

Demo https://rtcamp.github.io/web-story-creation-tool
JavaScript
16
star
27

wp-menu-custom-fields

An example of custom fields for menu in WordPress 5.4+
TypeScript
16
star
28

woobench-woocommerce-load-testing

WooCommerce Benchmarking
Python
14
star
29

gitlab-to-github-migration

Migrate GitLab project to GitHub
PHP
12
star
30

rt-lib

rt-lib is (intended to be) collection of reusable PHP classes useful for WordPress plugin/theme projects
PHP
12
star
31

transcoder

This WordPress plugin, useful to transcode audio and video file from any format to mp3 and mp4 respectively. Also it will generate thumbnails of videos.
PHP
10
star
32

action-phpcs-inspection

GitHub Action for PHPCS inspection.
Dockerfile
10
star
33

rt-newrelic-browser

NewRelic Browser Monitoring (Real User Monitoring) WordPress
PHP
10
star
34

wp-plugin-bootstrap

A skeleton wordpress plugin to bootstrap & standardize your development
Shell
9
star
35

rtsyntax

A lightweight syntax highlighter for WordPress
CSS
9
star
36

visual-automation-backstop

Visual automation with Backstop JS
JavaScript
9
star
37

media-node

A node.js wrapper for ffmpeg. Made for https://github.com/rtCamp/buddypress-media but can be used in any project which needs FFMPEG
Shell
9
star
38

docs.rtcamp.com

Documentation for rtCamp projects/products
CSS
8
star
39

gutenberg-plugin-boilerplate

Simple Gutenberg Boilerplate for plugin development
JavaScript
8
star
40

wordpress-preview-revisions

WordPress Preview Revisions Plugin help editors to preview the revisions with exact same content that would look like on the frontend.
PHP
7
star
41

ninja-to-gravity

PHP
7
star
42

pwa-wordpress-plugin

WordPress Plugin to enable PWA features.
PHP
7
star
43

search-with-google

A plugin for replacing WordPress default search with Google Custom Search results.
TypeScript
7
star
44

httperf

httperf clone with fix for FD_SETSIZE (open file limit)
C
7
star
45

amp-admanager

Easy and hassle free Google Admanager amp-ad tags integration for all WordPress sites. (AMP and Non-AMP)
PHP
5
star
46

rtpanel-hooks-editor

rtPanel hooks editor plugin provides user-interface for rtPanel WordPress Theme Framework
PHP
5
star
47

my-comment-manager

Better comment management for wordpress
PHP
5
star
48

action-wordpress-org-plugin-deploy

Shell
4
star
49

web-stories-ad-tool

Ad creation tool for google web stories. https://rtcamp.github.io/web-stories-ad-tool
JavaScript
4
star
50

automate-slack-invite-gravityforms

GravityForms addon to invite a user on Slack automatically
PHP
4
star
51

blogger-to-wordpress

Blogger to WordPress Redirection Plugin
TypeScript
4
star
52

rtmedia-code-snippets

This is custom code library for rtMedia core and premium add-ons
PHP
4
star
53

gitlab-bulk-delete-users

Delete users in bulk from Gitlab setup using rake tasks
Ruby
4
star
54

wporg-api-client

WordPress.org API client built in node.js
JavaScript
3
star
55

dockerfiles

Various Dockerfiles in use by rtCamp.
Dockerfile
3
star
56

amp-onesignal-compat

A WordPress Plugin to add AMP compatibility to OneSignal – Web Push Notifications
PHP
3
star
57

pwa-extension

Enables PWA features such as add to homescreen, offline reading features.
PHP
3
star
58

api_playwright_utils

API Automation Testing with Playwright
JavaScript
3
star
59

integrate-woocommerce-gitlab

With this code users can connect GitLab to WooCommerce, users will get source code repositories access as a Guest, Reporter, Developer or Master
PHP
3
star
60

wp-cli-report-command

Lists the plugin and theme usage for a multisite
PHP
2
star
61

wercker-step-wordpress-svn

Wercker deploy step for wordpress.org plugin svn repo
Shell
2
star
62

rtbiz-helpdesk

PHP
2
star
63

migrate-wufoo-to-gravity-forms

Import content from wufoo to Gravity Form- Entries, Comments and attachments.
PHP
2
star
64

blocks-bento-variations

PHP
2
star
65

px-wp-insights

AMP Compatibility Database
JavaScript
2
star
66

amp-generic-compat

AMP plugin to provide generic compatibility for Elements with hide and show toggle feature
PHP
2
star
67

rtWidgets

Sidebar Widgets Collection for rtPanel Theme Framework mainly. Might work on other theme as well.
PHP
2
star
68

embed-google-drive

TypeScript
2
star
69

rtmoto

rtMoto Theme
PHP
2
star
70

mention-links

Plugin which brings Github style user @mentions and article #links to the WordPress
TypeScript
2
star
71

stripe-xero-csv

Export Stripe's balance affecting transactions in a CSV file, recognisable by Xero Import CSV Statement feature.
PHP
2
star
72

action-deploy-frappe

Shell
2
star
73

edit-flow-slack-integration

This plugin is to send slack notification when editotial comment added.
PHP
1
star
74

lando-wordpress-skeleton

PHP
1
star
75

action-deploy-on-managed-instance

Shell
1
star
76

amp-infinite-scroll

AMP plugin for infinite scroll
PHP
1
star
77

web-stories-playground

JavaScript
1
star
78

rtAdmin

PHP-CLI nginx vhost creation script. Succeeded by https://github.com/rtCamp/easyengine
PHP
1
star
79

rtAntiSpam

WordPress login/register sidebar widget with recaptcha support
PHP
1
star
80

wp-cls-terminator

Remove CLS from Block Editor Embeds
JavaScript
1
star
81

gravityforms-sfmc-data-extension

Gravity Forms add-on to send entry data to a Salesforce Marketing Cloud Data Extension
PHP
1
star
82

rt-google-analytics-scroll-tracking

Integrates jquery-scrolldepth with Google Analytics by Yoast
JavaScript
1
star
83

amp-colormag-compat

Adds Compatibility to WordPress ColorMag theme.
PHP
1
star
84

gitolite-setup

Setup scripts for Gitolite v3
Shell
1
star
85

AMP-Extensions-Mini-Plugins

Monorepo contains different AMP extension plugins
PHP
1
star
86

psat-demos

EJS
1
star
87

rtmedia-transcoding-service-old

rtmedia Transcoding Plugin for rtMedia and WordPress Media Library
PHP
1
star
88

rt-react-theme

JavaScript
1
star
89

amp-email-subscribers

AMP compatibility for Email Subscribers & Newsletters – Simple and Effective Email Marketing WordPress Plugin by icegram
PHP
1
star