Skip to content

Front-end

Library

Defined in moderation_note.libraries.yml:

  • Library: moderation_note/main
  • JS: js/moderation_note.js
  • CSS: css/moderation_note.css (component)
  • Dependencies: core/drupal.dialog.off_canvas, core/once

Attached by hook_preprocess_field() on supported fields (see Hooks and events).

Behavior (JS)

  • Selection: On notable fields (with data-moderation-note-field-id and optionally data-moderation-note-can-create), text selection shows an “Add note” tooltip.
  • Add / reply / remove: Actions use Ajax and open off-canvas dialogs. Server returns Ajax commands that update the DOM (e.g. add/remove note highlights).

Ajax commands

Class Purpose
Drupal\moderation_note\Ajax\AddModerationNoteCommand Add a note highlight and related UI after creating a note.
Drupal\moderation_note\Ajax\ReplyModerationNoteCommand Add a reply in the UI.
Drupal\moderation_note\Ajax\RemoveModerationNoteCommand Remove a note highlight (e.g. when a note is deleted or resolved).

Files: src/Ajax/AddModerationNoteCommand.php, src/Ajax/ReplyModerationNoteCommand.php, src/Ajax/RemoveModerationNoteCommand.php.

Templates

Template Purpose
templates/moderation_note.html.twig Default note display (author, text, quote, actions, etc.).
templates/moderation_note--preview.html.twig Preview view mode.
templates/mail-moderation-note.html.twig Email body for notifications. Override in theme to customize.

Preprocess: template_preprocess_moderation_note() in moderation_note.module (variables: moderation_note, text, quote, author_, assignee_, actions, etc.).

View builder

Drupal\moderation_note\ModerationNoteViewBuilder — builds the render array for a moderation note entity (view mode full, preview, etc.).

Cache

  • Tags: moderation_note, moderation_note:{entity_type}:{entity_id}, moderation_note:{entity_type}:{entity_id}:{field_name}:{langcode}, moderation_note:user:{uid}.
  • Contexts: user.permissions, user, url.query_args (where used).
  • Notes invalidate their field’s cache tags on insert; entity delete invalidates notes for that entity.