Issue #3586478: "Add rich-text image description support to AI Automators"

Description

Ports the resolution of #3586478 from the 1.x line to the 2.x branch.

This introduces rich-text image awareness to AI Automators so supported text-based automators can discover embedded images, generate AI image descriptions, include those descriptions in prompt context, and optionally store image metadata for auditability.

For AI content pre-moderation, this enables the moderation automator to evaluate visual content from Article body fields in addition to text content. If embedded images cannot be fully processed (for example, configured image limit exceeded, unreachable/invalid external image, or provider-side processing failure), moderation is forced to flagged so a human editor can review.

The feature remains opt-in and scoped: image handling is encapsulated in RichTextImageDescriptionTrait and used by relevant formatted-text automators and LlmModerationState, rather than being applied globally to all RuleBase plugins.

Testing instructions

  1. Create a standalone Page-based automator test (outside moderation recipe scope):
  • Add two fields to page:
    • field_ai_image_summary (text_long) for generated output
    • field_ai_img_meta (string_long) for image metadata JSON
  • Create AI Automator config node.page.field_ai_image_summary.image_summary_test:
    • rule: llm_text_long
    • target field: field_ai_image_summary
    • base field: field_content
    • include image descriptions: enabled
    • include external images: enabled
    • max images: 3
    • metadata field: field_ai_img_meta
    • prompt includes {{ context }}
  1. Verify image processing and output:
  • Create/edit a Page node with field_content containing up to three image media references or <img src="https://..."> tags, then save.
  • Confirm field_ai_image_summary is generated using image-aware context.
  • Confirm field_ai_img_meta stores JSON metadata rows for processed images.
  • Reduce max images (for example to 1) and save again to confirm incomplete-analysis metadata is recorded and warning behavior appears in context-dependent output.
  1. Verify moderation fallback behavior:
  • Configure llm_moderation_state automator with image descriptions enabled.
  • Provide content where at least one eligible image cannot be fully analyzed (or exceed max image limit).
  • Confirm resulting moderation state is forced to flagged (when the state exists in workflow) and explanation storage behavior matches configuration.
  1. Automated checks:
  • Run relevant AI Automators unit tests:
    • AiAutomatorEntityModifierDecisionTest
    • RichTextImageHelperTest
    • RichTextImageDescriptionFailureTest
    • RichTextImageDescriptionTraitTest
  • Run coding standards checks for changed files (PHPCS).

Checklist

  • I have linked the related issue in the MR title or description
  • I have performed a self-review of my own code
  • I have added or updated tests, or explained in the description why this change is not covered by tests
  • I have updated documentation for any new or changed functionality
  • I have written testing instructions and verified them locally
  • I have noted any required post-merge steps (config imports, cache rebuilds, manual changes)
  • This MR contains no breaking API or hook changes, or they are explicitly documented in the description

AI Compliance

Note

Check the one that best describes your usage, or leave all unchecked if AI was not significantly used.

  • AI Assisted Code
    Mainly written by a human; AI used for autocomplete or partial generation under full human supervision.

  • AI Generated Code
    Mainly generated by AI, reviewed and approved by a human before this MR was created.

  • Vibe Coded
    Generated by AI and only functionally reviewed before this MR was created.

Closes #3586478

Merge request reports

Loading