Overview
This is one of the config entity types XB needs — see #3444424: [META] Configuration management: define needed config entity types.
For version 0.2, XB needs to be able to modify the page template (aka page.html.twig).
(See #3455753: Milestone 0.2.0: Early preview.)
Product requirement 19. Modify the page template (i.e. global sections) states:
As a builder, I want to modify the page template (i.e. page.html.twig). When I modify the page template, I can place components globally to global regions like navigation, header, footer, etc.
Designs + UX still needed. This is merely laying the technical groundwork inferred from that product requirement, and clarified by talking to @lauriii and @effulgentsia.
There are two distinct needs:
- Short-term/for existing sites and themes: ability to use Experience Builder to populate a theme's existing regions (which are essentially "slots" in the
page.html.twigtemplate). - Long-term: ability to not use a theme's
page.html.twig, and just craft that from scratch
Out-of-scope, follow-up issue needed:
- can be listed/read by the UI using a HTTP API: #3479982: HTTP API to read+write PageTemplate and Pattern config entities
- can be created by the UI using a HTTP API: #3479982: HTTP API to read+write PageTemplate and Pattern config entities
Proposed resolution
See the updated docs/config-management.md.
In a nutshell:
- new strictly validated
PageTemplateconfig entity type, with thorough config validation (and config dependency) test coverage inPageTemplateValidationTest()— which reuses the pre-existing validation logic for thetype: experience_builder.component_treeconfig schema type - that includes a new validation constraint that ensures the presence of certain essential page-level components (blocked on #3475584: Add support for Blocks as Components but proven to work in this MR) as well as ensure the absence of prop sources that cannot reliably work at the page level dynamic prop sources) — this validation constraint will also be usable in #3479643: Introduce a `Pattern` config entity, which this hence blocks
- new
\Drupal\experience_builder\Plugin\DisplayVariant\PageTemplateDisplayVariantpage display variant plugin with thorough functional test coverage in\Drupal\Tests\experience_builder\Functional\PageTemplateVariantTest
👆 This will allow reliable use of config management (#3444424: [META] Configuration management: define needed config entity types).
User interface changes
None.
Issue fork experience_builder-3478537
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
johnwebdev commentedI have a question that I’ve been thinking about around this, maybe a bit early to answer
Let’s say I have a header region, and I place a Hero component in that region. The Hero component requires an background image (Media entity)
How will that work? Let’s say I build the page template locally and then push the config entity to production, there is no guarantee that the media with that ID exists so the default will be broken image when you create a page.
Thinking loudly… Should page templates e.g be allowed to save “incomplete” components, or do we need some placeholder feature generic, or specifically for media?
Comment #6
wim leersThis is progressing nicely. An incomplete
PageTemplateconfig entity now fails as expected:(Also crediting Lauri & Alex.)
Comment #7
catchThe way this works with similar things now is you would have to do this:
1. Create the media entity on production
2. Sync the production database locally
3. Set up the layout (or whatever config entity referencing the content entity).
4. Deploy the config and everything works
This works but is of course very clunky. Feels like a separate issue since it's more of a general problem with config entities that reference content entities rather than XB specific, although agreed it's going to be a common thing people want to do.
Comment #8
wim leers#3: @catch is right in #7 and is also right that this is out of scope here, but merits its own issue. For now, let's discuss this on the meta, because this is a challenge affecting multiple of XB's config entity types. See prior discussion at #3444424-4: [META] Configuration management: define needed config entity types from >4 months ago, where I link to a PoC that we built >5 months ago that shows a viable way to fix that.
Let's not discuss that further here 🙏
Comment #9
wim leersWill continue on Monday, but this is ready for an initial high-level review. 👍
Comment #10
wim leersContinuing…
Comment #11
wim leersComment #13
longwaveA few questions but mostly nits, I think the overall approach is sound.
Comment #14
longwaveComment #15
wim leers@lauriii A review from @longwave surfaced two important questions, and I answered both by adding explicit "warning, future stuff" docs for both. Can you confirm the accuracy of these 2 small paragraphs? 🙏
Comment #16
lauriii#15: That looks good 👍 Those are limitations I'm aware of for the current state of XB.
Comment #17
wim leersThanks @lauriii! Incorporated your suggested refinement too 👍
All feedback from @longwave has now been addressed, back to him for review.
Comment #18
catchI did a (fairly quick/cursory) review of this and couldn't see any obvious problems, just one question in the MR.
Comment #19
wim leersGood question/suggestion, @catch! Responded :)
Comment #20
wim leersThe HTTP API follow-up exists: #3479982: HTTP API to read+write PageTemplate and Pattern config entities.
Comment #21
wim leersMerged in upstream and did a trivial search-and-replace to compensate for #3480193: Replace plus with dot in Component config entity IDs having landed.
Comment #22
wim leersFYI: #3479982: HTTP API to read+write PageTemplate and Pattern config entities is making good progress and will allow a (client-side) UI to be built, allowing to reuse significant pieces of the existing UX :)
Comment #23
wim leersFollow-up created per @lauriii's feedback: #3481188: [later phase] Gracefully handle deleted regions in PageTemplate config entities".
Comment #24
longwaveAgain only another round of tiny nits, I still think this is a solid base for the desired functionality here.
Comment #25
longwaveThanks, this looks great now, and unblocks future work. Let's ship it!
Comment #27
wim leers