Overrides for Drupal Mercury Editor.
Mercury Editor's tempstore-backed editing session has a few rough edges on multi-editor sites. This module patches them:
- Concurrent-edit detection. Mercury Editor forces the entity's
changedtimestamp on every form validate, which defeats Drupal core's optimistic-locking check. This module restores it: it swaps in a param converter that keeps the tempstore's original base version on a save request, and a form validation handler that compares it against the live database row, so a user gets "content has been updated by another user" instead of silently overwriting someone else's edit. On a plain read request it does the opposite — a stale tempstore entry is discarded in favor of a newer database version (e.g. saved via the standard edit form, a bulk action, or another user), and a tempstore entry pointing at a deleted entity 404s instead of resurrecting it. - Published checkbox. The Gin admin theme relocates the "Published" checkbox into markup that only its own page/form templates print. Mercury Editor renders neither, so the checkbox silently disappears from the editor tray; this module puts it back.
- State dropdown. The publishing state - the moderation state on bundles in a workflow, the "Published" checkbox otherwise - is shown as a dropdown in the editor toolbar, left of "Save", so it stays visible with the tray collapsed. Picking a state only takes effect on "Save"; a dot on the dropdown marks an unsaved change. The field itself stays in the tray where the form display puts it, and the two stay in sync both ways. The sidebar's read-only "Published"/state line is hidden when the dropdown shows it. Without JS the field in the tray still works on its own, and a user who can't change the state gets no dropdown.
- Admin toolbar. Mercury Editor hides the admin toolbar on its editor route by default; this module keeps it visible so editors retain normal site navigation while editing.
- 404/403 chrome. Suppresses Mercury Editor's page template on system error pages, where it doesn't apply.
- Component attributes audit. Warns (log, plus an on-page banner when
Twig debug is enabled) when a Layout Paragraphs component's Twig
template doesn't forward the
attributesvariable — Layout Paragraphs/Mercury Editor need it to track the component for drag-reorder, edit and save. - View button. Replaces the Mercury Editor logo in the editor toolbar with a "View" button that opens the entity's live canonical page in a new tab. Unlike "Done" — which navigates away and discards any tray edits never persisted through the toolbar "Save" — this is a safe way to check the current published page without leaving the editing session. Only shown once the entity has been saved at least once.
This module was extracted from a project-specific edw_mercury_editor
module.
Add this repository to your project's composer.json and require it:
"repositories": [
{"type": "vcs", "url": "https://github.com/eaudeweb/edw_mercury_editor.git"}
]composer require eaudeweb/edw_mercury_editor
drush en edw_mercury_editor
The active theme must define two libraries, named after the theme (e.g.
for a theme called mytheme: mytheme/edit_screen and
mytheme/mercury_editor_preview):
edit_screen: styles for the editor chrome — toolbar, dialogs and the tray around the preview iframe. Attached to thepage--mercury-editorpage.mercury_editor_preview: styles for the document rendered inside the preview iframe (e.g. rules targeting Layout Paragraphs builder markup like.js-lpb-component). Attached only whilemercury_editor.contextreports the current request as a preview, since the preview is a separate document from the editor chrome.
If a theme doesn't define these libraries, Drupal silently drops the missing library from the page's asset list — no error, no log entry. The editor and preview just render unstyled until the libraries are added.