Steps to reproduce

Drupal AI 1.3.0 introduced Field Widget Actions — one-click AI capabilities embedded directly in content fields. Currently there is no way for content editors to quickly assess the empathy quality of AI-generated text on a content form. Editors must copy text, navigate to the empathy module, and manually evaluate. There is also no integration with Drupal's content moderation workflow to gate AI-generated content based on empathy quality.

Proposed resolution

Add empathy evaluation to the content editing workflow:

1. Field Widget Action plugin (`CheckEmpathyAction`): A one-click "Check Empathy" button that appears on text fields. Clicking it scores the current field text using `EmpathyScoringService::scoreResponseGeneral()` and displays scores in a modal dialog.
2. Submodule at `modules/ai_empathy_field_action/` with dependency on `field_widget_actions` and `ai_empathy`. Keeps it optional.
3. Pre-publish empathy check: For AI-generated content going through moderation, optionally run an empathy assessment and attach the score to the moderation transition.
4. Moderation state gating: Configuration option to block content from being published if its empathy score falls below configured thresholds.
5. Visual feedback: Display empathy scores as colour-coded badges (green/orange/red) in the field widget after scoring.

Remaining tasks

- [ ] Create submodule `ai_empathy_field_action` with info.yml
- [ ] Implement `CheckEmpathyAction` Field Widget Action plugin
- [ ] Build AJAX callback to score text and return modal with results
- [ ] Add visual score badge rendering in the field widget
- [ ] Optional: Add moderation workflow integration
- [ ] Write tests
- [ ] Manual testing on content forms

Issue fork ai_empathy-3583742

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

joshua1234511 created an issue. See original summary.

joshua1234511’s picture

joshua1234511’s picture

Version: 1.0.2 » 1.0.3
joshua1234511’s picture

Assigned: Unassigned » joshua1234511

Implementation plan

Approach: ship this as an optional submodule modules/ai_empathy_field_action/ so the field_widget_actions coupling stays out of the main module. The submodule's .info.yml hard-declares dependencies: field_widget_actions:field_widget_actions and ai_empathy:ai_empathy; the parent module gains no new dependency. Core ^10.4 || ^11 || ^12; requires drupal/field_widget_actions:^1.3 (stable 1.3.0).

1. Field Widget Action plugin — CheckEmpathyAction

Defined with the #[FieldWidgetAction(...)] attribute (the module's plugin API — not a form alter / render key), targeting text widgets/fields: widget_types: [string_textfield, string_textarea, text_textfield, text_textarea, text_textarea_with_summary], field_types: [string, string_long, text, text_long, text_with_summary].
Extends FieldWidgetFormActionBase; on click it reads the field's current text and scores it, returning an AJAX OpenModalDialogCommand with the result.
Reuses the existing scenario-less scorer — EmpathyScoringService::scoreResponseGeneral($text) (already added for the guardrail submodule), which returns empathy_alignment and explanation_quality (1–5). No scenario required, so this works on any content field. DI mirrors EmpathyScoreGuardrail::create().
2. Visual feedback (badges)

Colour-coded badge (green / orange / red) driven by the existing global ai_empathy.settings:empathy_alignment_threshold (default 3.0): green at/above threshold, orange within ~0.5 below, red well below. Modal reuses the module's score-display conventions.
3. Content moderation gating (in the same submodule, activates only when core content_moderation is enabled)

Pre-publish empathy check on moderated entities and a block-below-threshold guard on the publishing transition, using the same threshold. Guarded via moduleHandler->moduleExists('content_moderation'); moderation-specific config shipped in config/optional/.
Notes from the field_widget_actions issue queue (handled in build):

#3567974 — action buttons can trip required-field validation; the check button will use #limit_validation_errors.
#3578204 — checkbox/radio widgets unsupported → we target text widgets only.
Deprecated multiple attribute param avoided; pinning ≥1.3 which includes the suggestion.js event fix (#3578820).
Testing: Unit test for threshold→badge logic; Kernel/Functional tests for the plugin scoring path, the modal AJAX response, and the moderation publish-gate (skipped when content_moderation is absent).

Related: https://www.drupal.org/project/ai_empathy/issues/3583745 (rating system), roadmap https://www.drupal.org/project/ai_empathy/issues/3583747.

joshua1234511’s picture

  • 5ad77eb0 committed on 1.0.x
    Issue #3583742: Add one-click Check Empathy field widget action and...
joshua1234511’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

joshua1234511’s picture

Status: Fixed » Closed (fixed)