[wp-trac] [WordPress Trac] #47375: Blocks API: Add server-side `serialize_block()`

WordPress Trac noreply at wordpress.org
Tue Jun 4 20:01:25 UTC 2019


#47375: Blocks API: Add server-side `serialize_block()`
--------------------------------------+------------------------------
 Reporter:  dmsnell                   |       Owner:  (none)
     Type:  enhancement               |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  Editor                    |     Version:  trunk
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------------

Comment (by birgire):

 > good call - I'll make sure this works and add the tests to verify it

 Thanks @dmsnell for the update

 > this comes with a symmetry to the JavaScript function of the same name.
 these are each one half of the > parser/printer pair that establishes our
 ability to reliably store the data in HTML form.
 > I think I'd lean towards keeping it for the sake of consistency across
 the platforms (JS vs. PHP).

 ... and for the link and clarification on the choice of the function's
 name. It makes sense.

 What about adding a note to the new functions here, that they are not
 related to the {{{serialize()}}} function in PHP?

 I wondered about the {{{'innerHTML'}}} part, as it was not in
 [attachment:"47375.patch"], but I see it's been introduced in
 [attachment:"47375-3.patch"].

 What about invalid {{{$block}}} input of {{{serialize_block( $block )}}} ?

 e.g. if {{{$block}}} is not an array or {{{$block['innerHTML']}}} array
 key is missing, then it looks like we would get a PHP notice there.

 Same with the {{{null === $block['blockName']}}} check in
 [attachment:"47375-3.patch"], seems to assume that the array key exists.
 It will give a PHP notice if it doesn't. Played with it here
 https://3v4l.org/5Vjh3

 What do you think about making sure the input has the correct structure?

 Thanks for the updated patch @jorgefilipecosta.

 Here are few suggestions to [attachment:"47375-4.diff"]:

 - Missing end of line (dot) in few places (also in test file).
 - I think it would be beneficial to the docs to add a more detailed
 description (i.e. the array keys {{{blockName}}}, {{{attrs}}},
 {{{innerHTML}}} and {{{innerContent}}}) belonging to the block's input:
 {{{@param array $block The block being rendered.}}}
 - Same for {{{* @param array $blocks The list of parsed block objects.}}}
 - What about adding {{{@covers ::serialize_block()}}} to the test class
 description, as all current tests are for the {{{serialize_block()}}}
 function?
 - If added, then I think one could simplify the description of test
 methods, e.g.: {{{* Test: test_serializes_and_strips_away_core_namespace()
 should serialize and strip away core namespace.}}} to
  {{{ * The function should serialize and strip away core namespace.}}}

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


More information about the wp-trac mailing list