Problem/Motivation
The Display Builder clipboard currently stores only a node ID reference in browser localStorage, scoped by builder instance entity ID:
localStorage key: "Drupal.{instance_id}"
value: {"copy": {"id": "abc123def456", "title": "My Component"}}
Copy is a purely client-side operation (no server request). When pasting, the server fetches the full component subtree by node ID from the current builder instance via getNode(). This means the clipboard is meaningless outside the current builder instance — the stored node ID refers to nothing on a different page.
Steps to reproduce
1. Edit a node translation (e.g. English) in Display Builder
2. Copy a component (right-click → Copy)
3. Navigate to another builder instance (different entity, or different language of the same entity that has a separate builder)
4. Right-click → Paste → nothing happens (paste is disabled because copyInstance.id is null under the new instance's localStorage namespace)
Proposed resolution
1. New API endpoint POST /api/display-builder/{instance}/_node/{node_id}/clipboard — returns the full subtree via SourceTree::getNode() as JSON
2. Copy flow: HTMX POST to the new endpoint → server returns JSON → JS stores in global Drupal.display_builder_clipboard (namespaced by project, not by instance)
3. Paste flow: JS reads global clipboard → passes source_data in request body → server uses it if present, falls back to getNode() for backward compatibility
4. Old clipboard format (just {id, title}) degrades gracefully: paste is disabled when no data field exists
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork display_builder-3612449
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
mogtofu33 commentedWe have pattern preset to create and share parts built with components, blocks, styles and config...
Furthermore presets handle context, if I copy something with an entity field, it will be available for entity view only.
So I think the feature is already here, unless I missed something?
Contextual menu actions related to a current builder only on purpose. Perhaps the copy is not currently restricted enough as it rely on local storage, will need a review after #3576683: [meta] UX refresh.