Gutenberg: Extensibility feature request: meta attributes from UI plugin

Created on 5 Apr 2018  路  5Comments  路  Source: WordPress/gutenberg

Issue Overview

In order to support, Jetpack's Publicize plugin from the pre-publish sidebar, I am looking into how to attach meta keys to a publishing post. In my specific case, Publicize needs to set the title for a social post and define the list of connections that should be shared to. The classic editor does this in the form data header:

image

Possible Solution

The current extensibility approach for editor plugins is to use registerPlugin to register a Fill component for some some slot in the UI. I would propose extending registerPlugin to allow the definition of an attributes field, just like registerBlockType. This could look something like the following:

registerPlugin( 'plugin-name', {
    render: Component,
        attributes: {
        author: {
                type: 'string',
            source: 'meta',
            meta: 'author'
        },
        },
} );

With this approach, the plugin could potentially set its associated attributes with setAttribute (as blocks do).

CC @aduth , @gziolo

Most helpful comment

I think this is already possible without another specific API.

you can do something like this to retrieve the attribute: const metaAttributes = wp.data.select( 'core/editor' ).getEditedPostAttribute( 'meta' )

and do something like this to update them: wp.data.dispatch( 'core/editor' ).editPost( { meta: newMetaAttributes } )

you can use withSelect and withDispatch Higher Order Components to provide these utilities as props to your component.

All 5 comments

I think this is already possible without another specific API.

you can do something like this to retrieve the attribute: const metaAttributes = wp.data.select( 'core/editor' ).getEditedPostAttribute( 'meta' )

and do something like this to update them: wp.data.dispatch( 'core/editor' ).editPost( { meta: newMetaAttributes } )

you can use withSelect and withDispatch Higher Order Components to provide these utilities as props to your component.

I agree with @youknowriad . To me, this seems like something which should be easier than it is now, but via the data module, not a dedicated API.

Oh great! I hadn't found that yet. Would it be good to document this somewhere (assuming it's not already somewhere that I overlooked)? Maybe in https://github.com/WordPress/gutenberg/blob/master/docs/attributes.md ?

Yes, it's not documented properly yet because we'd like to automate the selectors and actions documentation. The data module in itself is documented here though https://github.com/WordPress/gutenberg/tree/master/data

Thanks!

Was this page helpful?
0 / 5 - 0 ratings