Skip to content

For developers

The module has four extension points and a small set of services worth knowing about.

Extension point Attribute Discovered in Use it to
Review criterion #[ReviewCriterion] Plugin/ReviewCriterion/ Add a way of judging content, AI-backed or not.
Suggestion #[ReviewSuggestion] Plugin/Suggestion/ Add a kind of change a review can propose and apply.
Review record type #[ReviewRecordType] Plugin/ReviewRecordType/ Add a kind of thing that can be reviewed.
Agent tools #[FunctionCall] Plugin/AiFunctionCall/ Change or extend the contract an agent reports through.

How the pieces fit

flowchart TB
    Rule[ReviewRule config entity] -->|criteria| Crit[ReviewCriterion plugin]
    Rule -->|record_type| RT[ReviewRecordType plugin]
    Orch[ReviewOrchestrator] --> Crit
    Orch --> RT
    Crit --> Res[CriterionResult DTO]
    Res --> Orch
    Orch --> Rec[review_record entity]
    Orch --> Sug[suggestion entity]
    Sug --> SP[Suggestion plugin applies it]

Rules the module keeps

The orchestrator owns record creation. ReviewOrchestrator is the only class that creates review_record and suggestion entities. Controllers, forms, the queue worker and the action plugin all call it. Do not instantiate those entities yourself.

A criterion never throws. execute() must return a CriterionResult for every outcome, including failure. CriterionResult::failed() and CriterionResult::skipped() are there for that. An exception reaching the orchestrator is a bug in the plugin.

Suggestion plugins never save. apply() changes the entity in memory and returns. The caller saves, so several suggestions can be batched into one save.

Records are immutable. review_record and suggestion deny update and delete at two layers. The editor-state fields on a suggestion (applied_*, decision, decided_*, checked_off_*) are written through the entity's own setters from a controller, never through an entity form.

Thresholds and labels live outside the hash. InputHasher hashes only a criterion's configuration array. Anything stored as a sibling of it (label, short description, acronym, badge colour, pass and warn thresholds) can change without orphaning existing records. Anything inside configuration changes the question being asked, and existing records for that criterion go stale.

Review routes are dynamic. The ai_content_review.<entity_type_id>.review routes and the AI Review local task are built from the active Review Rules by ReviewRouteSubscriber and ReviewTabDeriver. Saving, deleting, enabling or disabling a rule flags the router for a rebuild.

Testing

# Everything
php vendor/bin/phpunit web/modules/contrib/ai_content_review/tests

# Unit only, no database
php vendor/bin/phpunit web/modules/contrib/ai_content_review/tests/src/Unit

# One class
php vendor/bin/phpunit web/modules/contrib/ai_content_review/tests --filter InputHasherTest

Kernel tests need drupal/ai installed. The module ships two test helper modules under tests/modules/: ai_content_review_test with a dependency-free criterion, and ai_content_review_stepping_test with criteria that exercise stepped execution.

Coding standards

vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,yml \
  web/modules/contrib/ai_content_review