Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern Directory: Allow container blocks to pass validation if they have child-blocks #85

Merged
merged 6 commits into from
Apr 27, 2021

Conversation

ryelle
Copy link
Contributor

@ryelle ryelle commented Apr 23, 2021

Fixes #82 — Container blocks were not considered valid, because the content they have in innerHTML is technically empty, the actual child block content is in innerBlocks. This updates the validation code to check into innerBlocks too, so groups and columns are correctly validated.

It also updates how paragraphs are validated - now any empty paragraph is considered "empty", even if the user maybe customized the font or color. A pattern should contain more content than just an empty styled paragraph.

How to test the changes in this Pull Request:

  1. Make sure the tests pass: yarn test:php or ✅ on the actions here
  2. Create a Block Pattern in wp-admin
  3. Add a group or column block, but don't change background color or any other attributes
    Or copy this content into the block editor (by switching to the code editor)
Group block code
<!-- wp:group -->
<div class="wp-block-group"><div class="wp-block-group__inner-container"><!-- wp:separator {"className":"is-style-default"} -->
<hr class="wp-block-separator is-style-default"/>
<!-- /wp:separator -->

<!-- wp:image {"align":"center","id":null,"width":150,"height":150,"sizeSlug":"large","linkDestination":"none","className":"is-style-rounded"} -->
<div class="wp-block-image is-style-rounded"><figure class="aligncenter size-large is-resized"><img src="https://s.w.org/images/core/5.8/portrait.jpg" alt="A side profile of a woman in a russet-colored turtleneck and white bag. She looks up with her eyes closed." width="150" height="150"/></figure></div>
<!-- /wp:image -->

<!-- wp:quote {"align":"center","className":"is-style-large"} -->
<blockquote class="wp-block-quote has-text-align-center is-style-large"><p>"Contributing makes me feel like I'm being useful to the planet."</p><cite>— Anna Wong, <em>Volunteer</em></cite></blockquote>
<!-- /wp:quote -->

<!-- wp:separator {"className":"is-style-default"} -->
<hr class="wp-block-separator is-style-default"/>
<!-- /wp:separator --></div></div>
<!-- /wp:group -->
Columns block code
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:paragraph {"style":{"typography":{"fontSize":"21px"},"color":{"text":"#000000"}}} -->
<p class="has-text-color" style="color:#000000;font-size:21px"><strong>We have worked with:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"style":{"typography":{"fontSize":"24px","lineHeight":"1.2"}}} -->
<p style="font-size:24px;line-height:1.2"><a href="https://wordpress.org">EARTHFUND™<br>ARCHWEEKLY<br>FUTURE ROADS<br>BUILDING NY</a></p>
<!-- /wp:paragraph -->

<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer --></div>
<!-- /wp:column -->

<!-- wp:column -->
<div class="wp-block-column"><!-- wp:spacer {"height":160} -->
<div style="height:160px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:paragraph {"style":{"typography":{"fontSize":"24px","lineHeight":"1.2"}}} -->
<p style="font-size:24px;line-height:1.2"><a href="https://wordpress.org">DUBAI ROOFS<br>MAY WATSON STUDIO<br>Y.O.L<br>RUDIMENTAR</a></p>
<!-- /wp:paragraph -->

<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
  1. Save the block pattern, it should successfully save, no validation errors.

@ryelle ryelle added the [Component] Pattern Directory The backend of the pattern directory: submission, management, etc label Apr 23, 2021
@ryelle ryelle added this to the Initial Launch milestone Apr 23, 2021
@ryelle ryelle self-assigned this Apr 23, 2021
@StevenDufresne
Copy link
Collaborator

It appears like self-closing blocks wouldn't pass. Not sure if that's intentional.

Tested using:

	/**
	 * Test valid block content: an archive block.
	 */
	public function test_valid_self_closing_block() {
		wp_set_current_user( self::$user );
		$response = $this->save_block_content( "<!-- wp:group --><div class=\"wp-block-group\"><!-- wp:archives /--></div><!-- /wp:group -->");
		$this->assertFalse( $response->is_error() );
	}

@ryelle
Copy link
Contributor Author

ryelle commented Apr 26, 2021

Hmmm, I think it's okay to leave. The goal is to make sure we're accepting patterns that are sufficiently customized, "Does it meet some minimum size/length? (At least one block with non-default attributes or content?)" (see #22).

If either the group or archive block in your example was customized, that would pass - like either of these:

<!-- wp:group {"backgroundColor":"pale-cyan-blue"} -->
<div class="wp-block-group has-pale-cyan-blue-background-color has-background"><!-- wp:archives /--></div>
<!-- /wp:group -->
<!-- wp:group -->
<div class="wp-block-group"><!-- wp:archives {"displayAsDropdown":true,"showPostCounts":true} /--></div>
<!-- /wp:group -->

The error message might be the problem. We could update the error message to say "Pattern content should be customized" or something like that— none of these strings should be considered final :)

@StevenDufresne
Copy link
Collaborator

The error message might be the problem. We could update the error message to say "Pattern content should be customized" or something like that— none of these strings should be considered final :)

Ah fair. I think that would be helpful.

Copy link
Collaborator

@StevenDufresne StevenDufresne left a comment

Choose a reason for hiding this comment

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

When you are ready.....

@ryelle ryelle merged commit 0ef99cc into trunk Apr 27, 2021
@ryelle ryelle deleted the fix/82-pattern-validation branch April 27, 2021 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Pattern Directory The backend of the pattern directory: submission, management, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Patterns in a plain group fail validation
2 participants