Skip to content

Approval Workflow ​

The flow Bouncer takes a save through, the database row that captures it, and the helpers on the entity that drive the UI.

How a save becomes a draft ​

user calls $table->save($entity, ['bouncerUserId' => $userId])
        │
        ▼
BouncerBehavior::beforeSave  (or beforeDelete for deletes)
        │
        ├── bypassBouncer option set? ─→ pass through, normal save
        ├── exemptUsers / bypassCallback matches? ─→ pass through
        ├── action not in requireApproval? ─→ pass through
        │
        ▼
serialize entity to JSON, write a bouncer_record row (status='pending')
        │
        ▼
short-circuit the original save (return false from beforeSave)
        │
        ▼
behavior remembers wasBounced() = true for the controller to read

On approval the flow runs in reverse: the bouncer_record's data payload is patched back onto a fresh entity from the source table, validated again (because draft validation isn't a substitute for save-time rules), and saved with bouncer bypassed for that specific call so it doesn't re-loop.

Re-edit deduplication ​

When the same user edits the same record again before the previous proposal was reviewed, Bouncer doesn't stack drafts:

  1. The controller calls loadDraft($primaryKey, $userId) and gets the existing pending row.
  2. The form is rendered with the draft's data overlaid on the published record.
  3. On submit, BouncerBehavior::beforeSave finds the existing pending draft for (source, primary_key, user_id) and updates it rather than inserting a new one.

Draft lookup includes the user ID, but auto-supersede applies to all pending proposals for the source and primary key. With its default value of true, a new proposal can supersede another user's draft. Set it to false to retain concurrent proposals from different users.

Database schema ​

The bouncer_records table stores one row per proposal:

ColumnTypePurpose
idintegerproposal primary key
sourcestringmodel name (Articles, Community.Stories for plugins)
primary_keyinteger / uuid / nullsource-record id, NULL for new-record proposals
user_idinteger by defaultwho proposed
user_displaystring / nulloptional display name for the proposer
reviewer_idinteger / null by defaultwho approved or rejected
reviewer_displaystring / nulloptional display name for the reviewer
statusstringpending / approved / rejected / superseded
dataJSONJSON-encoded text: new-record fields, dirty edit fields, or a delete marker
original_dataJSON / nullsnapshot of the source record at draft time — drives diffs and 3-way merge
original_modifieddatetime / nullsource record's modified timestamp at draft time — drives staleness detection
notestring / nullthe proposer's note explaining what they changed and why
reasontext / nullthe reviewer's note when approving or rejecting
created / modified / revieweddatetimethe usual lifecycle timestamps

primary_key is null for proposals that would create a new row. original_data is null for the same reason.

IMPORTANT

note and reason are two different fields with two different authors. The bundled admin viewer renders them as "User Note:" (the proposer's note) and "Reviewer Reason:" (the reviewer's reason). Don't conflate them — see Capturing a proposer note for how to populate note from your forms.

Status transitions ​

                ┌─────────┐
                │ pending │ ← every new proposal starts here
                └────┬────┘
            ┌───────┼───────┐
            ▼       ▼       ▼
    ┌────────────┐ ┌──────────┐ ┌────────────┐
    │  approved  │ │ rejected │ │ superseded │
    └────────────┘ └──────────┘ └────────────┘

Rows that leave pending are hidden from the default queue, but can be listed using status filters. The admin reopen action returns rejected rows to pending.

Entity helpers on BouncerRecord ​

The entity exposes predicates and accessors that the admin UI uses internally and that are useful in your own templates and custom flows.

Status predicates ​

MethodReturns
isPending()true when status === 'pending'
isApproved()true when status === 'approved'
isRejected()true when status === 'rejected'

Proposal-type predicates ​

MethodReturns
isNewRecordProposal()true when the proposal would create a row (primary_key is null)
isEditProposal()true when the proposal would modify an existing row
isDeleteProposal()true when the proposal would delete an existing row

These drive BouncerHelper::recordTypeBadge() — use them when you need the same branching in your own templates.

Data accessors ​

MethodReturns
getData()decoded proposed payload
getOriginalData()snapshot of the source record at draft time
hasMergedData()true if a custom merge result has been set
getMergedData()the explicitly-set merged payload, or the proposed payload if none

Staleness and merging ​

MethodReturns
hasOriginalModified()true if the row has an original_modified timestamp
canDetectStaleness()true if staleness can be evaluated (proposal is an edit + has original_modified)
isStale($currentSourceEntity)true if the source has moved since the draft was made
buildMergeResult($currentSourceEntity, $skipFields = ['id', 'created', 'modified', '_delete'])full 3-way merge result, or null if not stale
setMergedData(array $mergedData)override the apply payload (for UI-driven conflict resolution)
php
// Standard pattern: only render the merge UI when there's something to merge
if ($bouncerRecord->isEditProposal() && $bouncerRecord->canDetectStaleness()) {
    $current = $articles->get($bouncerRecord->primary_key);

    if ($bouncerRecord->isStale($current)) {
        $result = $bouncerRecord->buildMergeResult($current);
        if ($result['hasConflicts']) {
            // surface conflict UI; resolve into $mergedData; then:
            $bouncerRecord->setMergedData($mergedData);
        }
    }
}

UUID support ​

The source record key uses Polymorphic.type at migration time. Proposal IDs remain integers, and user/reviewer IDs default to integer columns. Configure source key types before installation and use application migrations for existing schema changes. See Configuration → Polymorphic Column Type.

Released under the MIT License.