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

Add allowedBlocks and TemplateLock attributes in Cover Block #31326

Merged
merged 4 commits into from Oct 16, 2021

Conversation

ajotka
Copy link
Contributor

@ajotka ajotka commented Apr 29, 2021

Description

According to #31312 request, I added allowedBlocks attribute for Cover Block.

How has this been tested? And Screenshots

Tested manually.

  • Without allowedBlocks (before changes & after changes with Cover without passing allowedBlocks attribute)
  • Expectations: Possibility to add all blocks

image (1)

  • With allowedBlocks = [ 'core/paragraph', 'core/heading', 'core/button' ]

  • Expectations: Possibility to add only Paragraph, Heading and/or Button
    image (3)

  • With templateLock

  • Expectations: No 'add block' button and no possibility to add block
    image (11)

Types of changes

  1. Add allowedBlocks and templateLock attributes with their types to block.json
  2. Add allowedBlocks and templateLock (default false) attributes to edit.js
  3. Add allowedBlocks and templateLock attributes to edit.native.js

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@ajotka ajotka requested a review from ajitbohra as a code owner April 29, 2021 10:08
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @ajotka! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Apr 29, 2021
@@ -306,6 +306,8 @@ function CoverEdit( {
minHeightUnit,
style: styleAttribute,
url,
allowedBlocks,
templateLock = false,
Copy link
Member

Choose a reason for hiding this comment

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

Setting a default here explicitly removes the locking even if the attribute is unset causing a behavior change. I think we should not include the default here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same default is in Column PR: https://github.com/WordPress/gutenberg/pull/25778/files
Maybe there is no problem, but I prefer to inform you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default value has been removed.

@skorasaurus skorasaurus added the [Block] Cover Affects the Cover Block - used to display content laid over a background image label May 3, 2021
Add an option to pass allowedBlocks to Cover Block.
Usage:
[ 'core/cover',
	  {
		allowedBlocks: ALLOWED_BLOCKS,
		templateLock: "insert",
	  },
	  []
],

Feature from WordPress#31312
@mkaz mkaz force-pushed the add/allowed-blocks-in-cover branch from 85b313b to b435d27 Compare October 16, 2021 19:40
Copy link
Member

@mkaz mkaz left a comment

Choose a reason for hiding this comment

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

This looks good.

I tested using a block filter to restrict what could be added.

wp.hooks.addFilter(
    'blocks.registerBlockType',
    'mkaz/testing-cover',
	function( settings, name ) {
		if ( name != 'core/cover') {
			return settings;
		}

		return {
			...settings,
			attributes: {
				...settings.attributes,
				allowedBlocks: {
					type: "array",
					default: [ 'core/paragraph', 'core/image' ],
				},
			}
		}
	}
);

This worked as expected with and without a templateLock value.

Thanks for the contribution! 👍

@mkaz mkaz merged commit 2303cd1 into WordPress:trunk Oct 16, 2021
@github-actions
Copy link

Congratulations on your first merged pull request, @ajotka! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@github-actions github-actions bot added this to the Gutenberg 11.8 milestone Oct 16, 2021
@Soean
Copy link
Member

Soean commented Oct 18, 2021

I think this is just a quick fix for the cover block. This feature is also useful for many other blocks. Maybe we should add it automatically via PHP to the Block API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Cover Affects the Cover Block - used to display content laid over a background image First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants