Skip to content

Conversation

@aduth
Copy link
Member

@aduth aduth commented Oct 5, 2018

The idea of this PR is to ensure previous templates still work while avoiding leaking the new RichText structure format into the format of the templates.

<?php

/**
 * Plugin Name: Demo CPT
 */

add_action( 'init', function() {
	register_post_type( 'book', [
		'label' => 'Book',
		'show_in_rest' => true,
		'public' => true,
		'show_ui' => true,
		'supports' => [ 'title', 'editor' ],
		'template' => [
			[ 'core/paragraph', [
				'content' => 'Hello <strong>world</strong>!',
			] ],
			[ 'core/paragraph', [
				'content' => [
					'Hello ',
					[
						'type' => 'strong', 
						'props' => [ 'children' => 'world' ]
					],
					'!'
				],
			] ],
			[ 'core/paragraph', [
				'content' => [
					'text' => 'Hello world!',
					'formats' => [
						null,
						null,
						null,
						null,
						null,
						null,
						[ [ 'type' => 'strong' ] ],
						[ [ 'type' => 'strong' ] ],
						[ [ 'type' => 'strong' ] ],
						[ [ 'type' => 'strong' ] ],
						[ [ 'type' => 'strong' ] ],
						null
					],
				],
			] ],
		],
		'template_lock' => 'all',
	] );
} );

@aduth aduth added the [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable label Oct 5, 2018
@aduth aduth requested review from ellatrix and youknowriad October 5, 2018 22:13
@mcsf mcsf added this to the 4.0 milestone Oct 8, 2018
@mcsf
Copy link
Contributor

mcsf commented Oct 8, 2018

Adding to 4.0 as we need a solid compat plan for RichText before releasing its format changes.

@gziolo gziolo added the [Priority] High Used to indicate top priority items that need quick attention label Oct 8, 2018
@gziolo
Copy link
Member

gziolo commented Oct 8, 2018

Can we prevent the following format from leaking into templates for posts and inner blocks?

			[ 'core/paragraph', [
				'content' => [
					'text' => 'Hello world!',
					'formats' => [
						null,
						null,
						null,
						null,
						null,
						null,
						[ [ 'type' => 'strong' ] ],
						[ [ 'type' => 'strong' ] ],
						[ [ 'type' => 'strong' ] ],
						[ [ 'type' => 'strong' ] ],
						[ [ 'type' => 'strong' ] ],
						null
					],
				],
			] ],

@youknowriad
Copy link
Contributor

I made some updates to this PR. The idea is to only support the "element/children" format for templates (which is what we currently do prior to 4.0) and also updates the code to avoid baking it in createBlock. Making it explicit that it's about templates.

Also, I'm fixing the "nested" attributes normalization (query sources) so, something like that would work:

add_action( 'init', function() {
	register_post_type( 'book', [
		'label' => 'Book',
		'show_in_rest' => true,
		'public' => true,
		'show_ui' => true,
		'supports' => [ 'title', 'editor' ],
		'template' => [
			[ 'core/paragraph', [
				'content' => 'Hello first paragraph!',
			] ],
			[ 'core/paragraph', [
				'content' => [
					'Hello ',
					[
						'type' => 'strong',
						'props' => [ 'children' => 'world' ]
					],
					'!'
				],
			] ],

			[ 'core/gallery', [
				'images' => [
					[
						'url' => 'https://picsum.photos/200/300',
						'caption' => [
							'Hello ',
								[
									'type' => 'strong',
									'props' => [ 'children' => 'world' ]
								],
								'!'
						]
					]
				],
			] ],
		],
		'template_lock' => 'all',
	] );
} );

@youknowriad youknowriad self-assigned this Oct 9, 2018
result[ key ] = [ result[ key ] ];
} else if ( ! Array.isArray( result[ key ] ) ) {
result[ key ] = [];
// the RichText getColorObjectByAttributeValuescomponent to handle the deprecated value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this copy and paste issue getColorObjectByAttributeValuescomponent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahaha :) sorry about that

@gziolo
Copy link
Member

gziolo commented Oct 10, 2018

Superseded by #10439.

@gziolo gziolo closed this Oct 10, 2018
@gziolo gziolo deleted the update/rich-text-normalize branch October 10, 2018 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Priority] High Used to indicate top priority items that need quick attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants