Paragraphs¶
frontend_editing_paragraphs adds paragraph support. Enable it when the content editors work on is
built from paragraphs.
drush en frontend_editing_paragraphs
Dependencies: frontend_editing, and
Paragraphs Edit.
What it adds¶
Paragraph lineage. A paragraph does not know its own host page; it knows its immediate parent, which may be another paragraph. The sub-module walks that chain to find the root entity, so saving a paragraph nested three levels deep saves the right node.
An add form that knows paragraph types. Choosing a type in the add panel creates the paragraph and splices it into the parent field at the right position.
Real duplication. Paragraphs belong to their host entity, so two field items can never point at one paragraph. Duplicating clones the paragraph into a new entity rather than adding a second reference to the same one, which is what the base module does for a plain reference field.
Translation handling. Paragraph translations follow their host's language handling when edited from the frontend.
Content moderation. Changes to paragraphs of moderated content are saved as a draft of the host. See Content moderation below.
Setup¶
The same three steps as any other bundle, applied to paragraph types:
- List the paragraph bundles under Entity types and bundles.
- Add the
extra_field_frontend_editingextra field to each paragraph bundle's view display. - Turn on the operations you want on the parent field's formatter, which is usually the paragraphs field on the node.
Remember that step 1 gates the referenced bundle. A paragraphs field on a node needs its paragraph
bundles listed, not node.
Contextual links¶
Paragraphs Edit depends on core's Contextual module, so paragraphs get contextual links as well as Frontend Editing links. The Hide contextual links setting removes the duplication. See Editing content.
Content moderation¶
Paragraphs are revisioned together with their host, so the sub-module makes Paragraphs Edit work with content moderation. See Content moderation for what editors see.
| Piece | What it does |
|---|---|
ModerationAwareLineageRevisioner |
Decorates paragraphs_edit.lineage.revisioner. Saves a change to a published host as a draft of the host instead of a new published default revision, and checks the transition on the root host before saving anything, so a refused change leaves no orphan paragraph revision. |
ActiveRevisionLineageInspector |
Decorates paragraphs_edit.lineage.inspector. Resolves parents to their active (latest) revision instead of the default one, so a second edit builds on the pending draft. |
ParagraphsReferenceHelper::getRevisionRoot() |
Follows the host revision a paragraph is rendered from (_referringItem), then falls back to the active root parent. Nested paragraphs resolve to the top host. |
RouteSubscriber |
Marks the root_parent and paragraph parameters of the paragraph edit and delete routes as load_latest_revision, so submitting a form does not upcast the published revision and save over the draft. |
FrontendEditingParagraphsHooks::addSaveModeButtons() |
On the paragraph edit and add forms (frontend_editing.form and frontend_editing.entity_reference_item_add routes), offers Save and publish and Save as draft when both are possible for the root host (RevisionHelperInterface::getSaveMode() is choice). The primary button follows the user's preference, the other one copies its submit handlers. setSaveMode() wraps them with RevisionHelperInterface::setPublishDirectly(TRUE/FALSE) and resets it to NULL afterwards, so ModerationAwareLineageRevisioner keeps the published state or saves a draft as the button says. It also adds the note and button tooltips that explain what saving does. |
ParagraphDeleteForm |
Keeps the paragraph entity when the host has a pending revision, because the published revision still references it. |
Warning
Decorating paragraphs_edit.lineage.revisioner and the inspector changes behaviour for every
Paragraphs Edit consumer once the sub-module is enabled, not only for frontend editing links.
Danger
Do not apply the Paragraphs Edit patch from
issue 2914976. Its moderation
state copy overwrites the draft state, and the parent then reads a $time property the
decorator never sets. Nothing enforces this.
The decorators extend the concrete Paragraphs Edit classes and skip their parent constructors,
because the 3.x and 4.x signatures differ. This was verified against Paragraphs Edit 3.0.1. The
4.x route names (entity.paragraph.edit_form, entity.paragraph.delete_form), its
createRevision() clone and its ParagraphLineageInspectorInterface type hint were only read, not
run.
Save queue (experimental)¶
Normally each paragraph edit saves on its own. The save queue lets an editor make several paragraph edits, and move, delete and duplicate actions, and commit them in one go.
Warning
This is experimental. Verify it on a development environment before enabling it in production.
Enable it under Save queue settings on the settings form. It needs All Entity Preview, whose tempstore holds the queued values. Without that module the endpoints stay registered but do nothing.
flowchart LR
Edit[Edit a paragraph<br/>in the sidebar] --> Queue[Add to Save Queue]
Move[Move, delete<br/>or duplicate] --> Pending[(Pending structure<br/>per host field)]
Queue --> Store[(Preview tempstore)]
Store --> Page[Page shows<br/>the unsaved values]
Pending --> Page
Queue --> More[Edit another<br/>paragraph]
More --> Queue
Store --> Save[Save All]
Pending --> Save
Save --> Entities[Host entities saved,<br/>queue cleared]
Each paragraph form in the sidebar gains an Add to Save Queue button next to Save. Queued paragraphs render on the page with their pending values, and a floating Save All button reports how many are waiting. Its position relative to the frontend editing toggle is the "Save All" button position setting.
The panel has a Revision log message field. Its text is set on the new revision of each root
entity. Left empty, the default "Updated with frontend editing." is kept. With content moderation,
saving the queue creates a draft of a published host, and is refused for a user who may not make
the transition. Users with the frontend editing publish directly permission get Save All and
publish and Save All as draft; the one that matches their preference comes first. A host that
may not be published directly, for example one with a pending draft, fails with Save All and
publish. A note above the buttons says what saving does, and the page says "Your changes were
published." after a direct publish.
Saving groups the queue by root entity and saves each group in its own database transaction, so one failing group does not half-write another. Items can also be discarded from the queue without saving.
Pending outline¶
With the save queue on, every bundle Frontend Editing is enabled for gets a data-preview attribute,
so a queued paragraph shows the dashed "pending" outline. The bundle does not need to be enabled in
the Preview module's settings.
Move, delete and duplicate in the queue¶
With the save queue on and All Entity Preview installed, move up, move down, delete and duplicate on a paragraph field are queued instead of saved. They do not change the stored host. Each action builds on the pending order, so several actions in a row add up, and the page shows that order.
The panel has one entry per field, such as "Sections on 'About us': 3 changes". The pending state is kept per user, per host and field, in the private tempstore. The × on the entry discards that field's structural changes and reloads the page. Paragraphs duplicated for it are deleted again.
Duplicate is the one exception to "nothing is saved": the clone is saved at once, but nothing references it until Save All. It can be edited and queued like any other paragraph.
Save All applies queued edits and structure together, in one transaction per root entity. With content moderation a published host gets one draft for the whole group, and the revision log message is set on the root. See Content moderation.
Note
If a queued edit is for a paragraph that a queued delete removes, the edit is not saved. Save All reports it as discarded.
The move, delete and duplicate links show no save mode (badge, tooltip) while they are queued, since nothing is saved until Save All, whose buttons say what will happen. Add and edit keep their save mode, as they still save immediately.
Without the save queue, nothing changes: the actions save immediately.
Warning
Known limitations of the pending structure:
- Add is not queued. It still saves immediately. Adding to a field with pending structure makes the next Save All refuse that host as changed (see below), and the new paragraph is not visible until the pending structure is discarded. The add position is computed from the pending order but checked against the stored order, so an add can be refused or land elsewhere.
- Changed hosts are refused. If the host got a new revision after the structure was queued, Save All refuses that root, keeps its items and shows an error. The other roots are still saved. Saving a paragraph form directly, outside the queue, while its host has pending structure does the same.
- The render cache does not vary per user, the same as for previews of unsaved values.
- Without JavaScript AJAX (the non-AJAX fallback) no queue entry is created.