Overview

Quoting #3454094: Milestone 0.1.0: Experience Builder Demo:

  1. As a content creator, I want to edit meta fields directly within the page builder interface. For example, the menu links and URL alias should be editable on the same page as the page builder.

(Saving these is out of scope — because it is out of scope for #3450586: [META] Back-end Kanban issue tracker too.)

Proposed resolution

  1. Route definition:
    experience_builder.api.entity_form:
      path: '/xb/api/entity-form/{entity_type}/{entity}/{entity_form_mode}'
      defaults:
        _form: '\Drupal\experience_builder\Form\EntityForm'
        _title: 'Entity Form'
      requirements:
        _permission: 'access administration pages'
      options:
        parameters:
          entity:
            type: entity:{entity_type}
    
  2. Retrieve $form['meta'] (see NodeForm) — more scalable solution to follow in #3463991: [RESEARCH] How to identify all meta fields for an arbitrary content entity?

    Per @lauriii in #6: use the route's "form mode" parameter, to load the appropriate form. The intent: start with the default node edit form, but allow defining a separate form mode + EntityFormDisplay for a more tailored UX. @lauriii expressed explicitly the desire for this parametrization, to allow not needing to redo this in the future.

    (Stepping through how /node/1/edit works, it's \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer + \Drupal\Core\Entity\Entity\EntityFormDisplay::collectRenderDisplay() that do the crucial pieces. But note how \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer::enhanceEntityView() does have an explicit mention of $defaults['view_mode'] = $view_mode;, but \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer::enhanceEntityForm() has no equivalent!)

  3. Explicit high-level test coverage for verifying this route returns form markup (BrowserTestBase, Cypress E2E test is impossible in this issue).
  4. Don't worry about CSS/JS assets for now: getting the form to load at all is the goal (there are other issues in progress that improve the asset loading parts).
  5. The expected request body should be documented in /openapi.yml.

User interface changes

None — we'll need a front-end sibling issue to actually use this. This is about allowing that front-end work to happen independently, about pre-emptively unblocking that.

Command icon 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

Wim Leers created an issue. See original summary.

wim leers’s picture

wim leers’s picture

Issue summary: View changes

Wim Leers credited lauriii.

wim leers’s picture

Title: HTTP API: new /xb/api/meta-form route to load form for editing entity meta fields » HTTP API: new /xb/api/entity-form/{form_mode} route to load form for editing entity fields (meta + non-meta)
Issue tags: +Needs issue summary update

After discussing this in-depth with @lauriii, he is requesting this pivot:

8. As a content creator, I want to edit meta fields directly within the page builder interface. For example, the menu links and URL alias should be editable on the same page as the page builder.
9. As a content creator, I want to edit fields directly within the page builder interface. For example, the title should be editable on the same page as the page builder. I expect the page title to be displayed in the preview.

should both be covered by this; with the widgets for all of the entity fields (except for the XB field) appearing in the right sidebar, and hence in a single form. IOW: everything in the default form mode/display.

But the implementation should allow specifying a form mode, to allow in the future requesting only the meta fields (TBD how to identify these: #3463991: [RESEARCH] How to identify all meta fields for an arbitrary content entity?), or only the "structured data" fields.

larowlan’s picture

Shouldn't the url also include entity type and id?

wim leers’s picture

Is it possible to naively identify meta fields by finding all fields that are not displayed in any view mode? This probably doesn't hold true for all cases, but generally, if a field is never displayed it must be meta information of some kind?

— @longwave at #3463991-7: [RESEARCH] How to identify all meta fields for an arbitrary content entity?.

Let's use that heuristic in this initial implementation 👍

wim leers’s picture

Title: HTTP API: new /xb/api/entity-form/{form_mode} route to load form for editing entity fields (meta + non-meta) » HTTP API: new /xb/api/entity-form/{entity_type}/{entity}/{entity_form_mode} route to load form for editing entity fields (meta + non-meta)
Issue summary: View changes
Issue tags: -Needs issue summary update +Needs tests, +openapi
wim leers’s picture

Assigned: Unassigned » tedbow

longwave’s picture

Status: Active » Needs work
StatusFileSize
new93.85 KB

The MR so far adds the route and a controller that returns the form HTML wrapped in JSON.

I tried to start writing a test but I get a 404 from /xb/api/entity-form/node/1 and I'm not sure why.

This will also need better access checking added to the route, but this is enough to get started.

tedbow made their first commit to this issue’s fork.

tedbow’s picture

got the test passing locally but looks I have update something for OpenApi spec to get the test to pass. Haven't had time to figure this yet

tedbow’s picture

Assigned: tedbow » wim leers
Status: Needs work » Needs review

I think this is ready

tedbow’s picture

Issue tags: -Needs tests
wim leers’s picture

Assigned: wim leers » tedbow
Status: Needs review » Needs work

A few questions about things that are unclear to me, but mostly requests for documenting the tricky things that you and @longwave identified/encountered :)

tedbow’s picture

Assigned: tedbow » wim leers
Status: Needs work » Needs review
wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs review » Reviewed & tested by the community

  • Wim Leers committed f7fae548 on 0.x authored by longwave
    Issue #3463988 by tedbow, Wim Leers, longwave, lauriii: HTTP API: new /...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.