Overview

@lauriii observed this:

It looks like the XB preview is now showing global regions but the actual main content is slightly different between the real site and XB. Is there still an additional step needed to render the node content using the display mode? FWIW, if this is difficult to do, it would be fine to handle this in a follow-up issue.

XB:

Actual page:

#3489302-26: Preview entire page not just content area

Root cause analysis by @Wim Leers:

That's because this MR is not rendering the main content block \Drupal\system\Plugin\Block\SystemMainBlock. This MR pretends the component tree for the current Node or Page is the main content, and then lets that "main content" be decorated by blocks — i.e. it still uses BlockPageVariant.

This is good enough for the Page entity introduced by #3482259: Landing page integration: new content entity type for unstructured content, because \Drupal\experience_builder\Entity\PageViewBuilder::alterBuild() only renders the component tree.

#3489302-28: Preview entire page not just content area

Updating ApiPreviewController like that was out of scope in #3489302: Preview entire page not just content area, this issue is the place to do that.

Proposed resolution

Proposal by @Wim Leers

For Node (and other content entities, and actually when editing the PageTemplate and looking at an arbitrary route), we need to reuse the original route (for editing a content entity that'd be its $content_entity->toUrl('canonical') route/link template) but replace/override/intercept the route parameter with one that reflects the values in the XB UI of the XB field (the component tree) and all other fields.

  • For content entities being edited through XB that means calling the controller with an EntityInterface object with all field values dynamically overridden compared to the saved (published) values. (For Node: \Drupal\node\Controller\NodeViewController::view() with a NodeInterface object.)
  • For arbitrary routes viewed in XB (to edit the regions for the active theme's PageTemplate — see #3489899: Add support for global regions), we don't need to do anything: it'd just be pass-through.

#3489302-28: Preview entire page not just content area

User interface changes

  • When editing a Page content entity in the XB UI: zero visual changes
  • When editing a Node content entity in the XB UI: the preview in the XB UI (first screenshot in #3489302-26: Preview entire page not just content area) looks exactly like the actual page (second screenshot in that same comment). IOW: the entire node.html.twig template shows up, including the author, "submitted by PERSON on DATE", the comments list and comment form.
  • ⚠️ Ideally, but may be postponed to a follow-up, because it ties into product requirement 18. Navigate between layers] the ability to point the XB UI at any route, which on all routes without a content entity without an XB field means that only the PageTemplate is editable and has the necessary affordances in the XB UI.

Comments

wim leers created an issue. See original summary.

wim leers credited lauriii.

wim leers’s picture

Crediting Lauri.

wim leers’s picture

Issue summary: View changes
wim leers’s picture

[…] replace/override/intercept the route parameter with one that reflects the values in the XB UI of the XB field (the component tree) and all other fields.

The closest I've ever built something like this is for, see MigrationPreviewer::buildPreview(). That's at the render array/entity view builder level, not the route/controller level. But it does generate a bona fide entity object, so it actually is comparable.

(I bet this can be implemented using a KernelEvents::REQUEST event subscriber that modifies the entity object that \Drupal\Core\ParamConverter\EntityConverter converted.)

wim leers’s picture

Title: [later phase] ApiPreviewController must use the previewed route's controller, and override canonical content entity routes' received entity object » [later phase] ApiLayoutController must use the previewed route's controller, and override canonical content entity routes' received entity object
Component: Page builder » Internal HTTP API
Parent issue: » #3521002: [META] Maintainable client-side data model + internal HTTP API

This controller was renamed somewhere along the way.

Ideally, we'd have this done sooner rather than later, for solid foundations.

Project: Experience Builder » Drupal Canvas
Version: 0.x-dev » 1.x-dev

Experience Builder has been renamed to Drupal Canvas in preparation for its beta release. You can now track issues on the new project page.