Skip to content

Review record type plugins

Review Records are bundled, and each bundle is a plugin. A record type answers everything the rest of the module does not want to know about what is being reviewed: how to identify it, how to access-check it, how to describe it to an AI, and how to write a suggestion back into it.

Two ship with the module:

ID Reviews Bundle fields
internal Any Drupal content entity entity_type, entity_id, entity_revision_id
external A remote source identified by a URL url

Internal records store their subject denormalised rather than as an entity reference, so a record survives the deletion of what it reviewed.

Add a plugin when you want to review something that is neither: a file in a DAM, a row in an external CMS, a product feed.

The plugin

Place the class in src/Plugin/ReviewRecordType/ and tag it:

#[ReviewRecordType(
  id: 'feed_item',
  label: new TranslatableMarkup('Feed item'),
  description: new TranslatableMarkup('Review record for an item in a syndicated feed.'),
)]
final class FeedItemRecordType extends ReviewRecordTypeBase {
  // ...
}

ReviewRecordTypeBase handles the boilerplate. Extend it rather than implementing the interface from scratch, and read ExternalReviewRecordType as the smaller worked example.

What a record type has to answer

buildFieldDefinitions() declares the bundle's own fields, using Drupal\entity\BundleFieldDefinition. The rest of the interface falls into four groups.

Identity

Method Answers
supports($subject) Is this mine? Answer on the shape of the subject alone, never throw. Exactly one bundle may claim any subject.
subjectKey($subject) A stable string naming the subject. This is what appears in review route URLs.
subjectKeyOf($record) The same key, derived from a record. The two must agree exactly.
subjectFromKey($key) The key turned back into a subject, or NULL when it names something that no longer exists.
subjectValues($subject) Field values to write onto a new record. Reject a subject you cannot fully describe: a half-populated record can never be matched again.

Run and triage routes address what is under review as a record type plus a subject key, which is why one set of routes serves a content entity and a URL alike.

Matching

Method Answers
subjectConditions($subject) Conditions matching records about this subject in this exact state, pinning a revision where the bundle has one. Used to find an in-flight run and to decide whether a result already exists.
subjectIdentityConditions($subject) Conditions matching every record about this subject, in any state. This is the history view.
subjectChangedSince($record, $subject) Is a fresh review worth paying for? A bundle that cannot compare returns TRUE, because not knowing is a reason to allow a re-run rather than forbid one.

For a subject with only one state, a URL for example, the first two return the same set.

Access and rules

Method Answers
subjectAccess($subject, $account, $operation) May this account read reviews of this thing (view) or write into it (update)? Route permissions say who may review at all. This says who may review this.
rulesFor($subject) Which Review Rules apply. Which criteria run against a thing is a property of the thing, so the bundle answers rather than the orchestrator guessing.

Talking to the AI, and writing back

Method Answers
buildReviewContext($record) The subject as text. How to describe it is bundle knowledge; what to ask about it stays with the criterion.
getTokenContexts($record) Token contexts an agent needs to act on the subject. An internal record hands over the live entity so tools can read and write its fields. These keys are stripped before an agent is serialised between turns, since a live entity does not round-trip through storage.
applySuggestion($subject, $suggestion) Writes one accepted suggestion and persists it. Throw \LogicException when the bundle's subjects cannot be written to, which is the honest answer for a read-only source.

Using it in a rule

Once discovered, the plugin's label appears in the Reviews select on the Review Rule form. The rule's Entity type and Entity subtypes fields only apply to internal rules, and your bundle's rulesFor() decides what narrowing, if any, your rules support.

Two limits to be aware of:

  • Cron only walks internal rules. There is no set of subjects to enumerate for a bundle whose subject is a URL, so scheduled passes do not apply unless your bundle can be enumerated and you add a trigger of your own.
  • The Views handlers are registered for Content (node_field_data) only.