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

Block variation: templateLock not working #64480

Closed
2 tasks done
huubl opened this issue Aug 13, 2024 · 2 comments · Fixed by #65105
Closed
2 tasks done

Block variation: templateLock not working #64480

huubl opened this issue Aug 13, 2024 · 2 comments · Fixed by #65105
Labels
[Block] Cover Affects the Cover Block - used to display content laid over a background image [Type] Bug An existing feature does not function as intended

Comments

@huubl
Copy link
Contributor

huubl commented Aug 13, 2024

Description

Setting the templateLock attribute to contentOnly in a block variation is not working.

Step-by-step reproduction instructions

  1. Register the "cover-locked" block variation using the provided code.
  2. Insert the "cover-locked" block into a post or page.
  3. Save the post or page.
  4. Reload the page.

Screenshots, screen recording, code snippet

wp.blocks.registerBlockVariation("core/cover", {
	name: "cover-locked",
	title: "Cover Block Variation Locked",
	description: "When reloading the page, the templateLock 'contentOnly' is lost.",
	category: "media",
	icon: "smiley",
	attributes: {
		templateLock: "contentOnly",
		useFeaturedImage: true,
		dimRatio: 0,
		backgroundType: "image",
		overlayColor: "",
		isUserOverlayColor: true,
		contentPosition: "center center",
		isDark: false,
		className: "is-cover-locked",
		tagName: "div",
		textColor: "white",
		layout: {
			type: "constrained",
			contentSize: ""
		},
	},
	innerBlocks: [
		["core/heading", {level: 1, placeholder: "When reloading the page, the templateLock 'contentOnly' is lost."}],
	],
	example: undefined,
	scope: ["inserter"],
	isDefault: false,
	isActive: ['className'],
});

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes
@huubl huubl added the [Type] Bug An existing feature does not function as intended label Aug 13, 2024
@talldan
Copy link
Contributor

talldan commented Aug 14, 2024

Thanks for reporting, I could reproduce it. It looks to be the same kind of issue we had for the group block recently (see - #63837).

There's a block deprecation that causes the attributes to be stripped:

isEligible( attributes ) {
return (
attributes.customOverlayColor !== undefined ||
attributes.overlayColor !== undefined
);
},
migrate( attributes ) {
return {
...attributes,
isUserOverlayColor: true,
};
},

The isElligible function is the main issue. customOverlayColor or overlayColor are currently in use and valid block attributes for the cover block, so I don't understand why this implementation checks for them. It causes the deprecation to match against perfectly normal use cases of the block.

The issue was introduced in #54054 (cc @ajlende)

@andrewserong
Copy link
Contributor

I think I have a fix for this over in #65105.

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 [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants