Skip to content

Block API: Block context render_callback not fully backward-compatible as array #21797

@aduth

Description

@aduth

Previously: #21467
Related: Automattic/jetpack#15515

As part of the implementation of block context in #21467, the function signature of render_callback was revised in such a way that was intended to be fully backward-compatible. It did so by creating a custom block class which implemented the PHP ArrayAccess interface, where attempting to access array members of the first argument would be proxied automatically to block attribute members, to simulate the same effect of the previous signature wherein an array of block attributes was passed. The intention was to seamlessly allow the argument to be used either as an instance of the block class, or as an array of a block's attributes.

Problem:

While implementing ArrayAccess is expected to satisfy a majority of common usage, it has become obvious that it does not faithfully uphold full backward compatibility. Some of these are rare and extreme edge cases, while others may be more common to anticipate.

Examples:

Possible Solutions:

Some options to consider include:

Personal preference: I'm most keen to see if there are options around method reflection, in order to avoid the addition of a new settings property while giving the developers the choice to explicitly opt in to the behavior of receiving the block instance. It is not clear to me yet if this is a viable option.

Action Plan:

If a decision amongst the above (or additional) options cannot be reached and implemented before this Friday, April 24, then #21467 should be reverted to allow more time to consider the decision, or at least parts which affect the public API of render_callback.

Metadata

Metadata

Assignees

Labels

Needs DecisionNeeds a decision to be actionable or relevant[Feature] Block APIAPI that allows to express the block paradigm.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions