Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Block API: Allow for internal, non-duplicable block attributes  #29693

@stacimc

Description

@stacimc

What problem does this address?

Blocks cannot use attributes to store information that is unique internal to the block instance but also persisted across page loads. Here's an illustrative example:

I'm working on the Jetpack Pay with PayPal block. It contains a productId attribute which uniquely identifies the actual product record referenced by the block. When a new block is inserted this attribute will be undefined; we hit the API to create a new product, and store the returned id in this attribute.

When the block is duplicated, I'd like to create a new product record with identical fields (title/price/etc). But because the productId is cloned along with all the other attributes, both blocks will point to the same resource. It's possible to keep track of the block's unique clientId and reset the product when this value changes — but while this detects block duplication, it also changes every time the post loads, and I only want to reset the product on duplication.

What is your proposed solution?

A couple of options as a starting point for discussion:

  1. Add support for unique internal attributes, which do not get copied during block duplication.
  2. Allow blocks to listen for/handle the duplication event.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Block APIAPI that allows to express the block paradigm.[Feature] BlocksOverall functionality of blocks[Type] New APINew API to be used by plugin developers or package users.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions