Skip to content

Block variation: templateLock not working #64480

Closed

Description

@huubl

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

Activity

  1. added
    [Type] Bug
    on Aug 13, 2024
  2. talldan commented on Aug 14, 2024

    @talldan
    Contributor

    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)

  3. added
    [Block] Cover
    on Aug 14, 2024
  4. andrewserong commented on Sep 6, 2024

    @andrewserong
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] Cover[Type] Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions