Since #2042773: Change #items within a theme_field() render array from an *array* to the same $items *object* used throughout the rest of the formatter pipeline, the render arrays for an entity contains field values as #items / FieldItemList objects, that themselves reference the $entity.
Serializing those should be avoided.
- CommentFormController and MessageFormController each embed the 'entity preview' render array in the $form, which then gets serialized
- NodeFormController embeds the result of node_preview() in the $form, but that is a fully rendered HTML string, not a render array.
Plus, the three implementations are largely different. Some unification in the ContentEntityFormController base class would help avoid contrib entity types that want to provide previews making the same mistakes.
Comments
Comment #1
yched CreditAttribution: yched commentedComment #2
yched CreditAttribution: yched commentedComment #3
catchCross-posting #1510544: Allow to preview content in an actual live environment.
Comment #4
sunThe root cause is that we're triggering the preview from within the
$form
processing code, instead of after.Theoretically, it should be possible to move the code into a #pre_render callback - i.e., out of the form processing flow and into the render flow.
Alternatively, by now we might have reached an architectural state in which the corresponding controller could perform the preview + output? Does it have to be within the form processing at all?
Comment #15
catchPretty sure #1510544: Allow to preview content in an actual live environment made this obsolete.