[wp-trac] [WordPress Trac] #59313: Implement Block Hooks

WordPress Trac noreply at wordpress.org
Mon Dec 4 20:24:55 UTC 2023


#59313: Implement Block Hooks
-------------------------------------------------+-------------------------
 Reporter:  Bernhard Reiter                      |       Owner:  Bernhard
                                                 |  Reiter
     Type:  enhancement                          |      Status:  closed
 Priority:  high                                 |   Milestone:  6.4
Component:  Editor                               |     Version:
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch gutenberg-merge has-unit-  |     Focuses:
  tests commit                                   |
-------------------------------------------------+-------------------------

Comment (by Bernhard Reiter):

 In [changeset:"57157" 57157]:
 {{{
 #!CommitTicketReference repository="" revision="57157"
 Block Hooks: Store ignored hooked blocks metadata in anchor block.

 The biggest tradeoff that was made in the implementation of Block Hooks
 was that they were limited to layouts (i.e. templates, template parts, and
 patterns) that ''didn't have any user modifications'' (see #59313 for the
 reason). This changeset is a preparatory step to remove this limitation,
 so they’ll eventually also work with user-modified layouts.

 The crucial problem to solve is how to acknowledge that a user has opted
 to remove or persist a hooked block, so that the auto-insertion mechanism
 won't run again and inject an extraneous hooked block on the frontend when
 none is solicited.

 This is achieved by storing all known blocks hooked to a given anchor
 block in the `metadata` attribute on that anchor block; specifically in a
 field called `ignoredHookedBlocks` inside of the `metadata`. Hooked blocks
 are only rendered on the frontend if they're absent from that field; OTOH,
 they're injected into that field (via the REST API) when first loaded in
 the editor.

 This simple logic guarantees that once a user modifies a given layout,
 those changes are respected on the frontend; yet if a plugin that includes
 a hooked block is activated after those modifications have taken place,
 the hooked block will be rendered on the frontend. This new technique
 supplants the one previously used (i.e. rendering hooked blocks on the
 frontend only if a layout doesn't have any modifications) in a rather
 direct way.

 Note that this changeset only introduces the new metadata field and
 relevant logic; it does not yet enable hooked block insertion into
 modified layouts. That will be done in a subsequent step (see #59646).

 Props gziolo.
 Closes #60008.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59313#comment:117>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list