Understanding Revisions in Drupal
In Drupal, revisions (or versions of content) allow you to track changes over time. Every time an editor saves content, a new revision can be created.
Example:
- An editor publishes an article → Revision #1 is created (default).
- A week later, the editor updates the article → Revision #2 is created (becomes default).
- The database keeps both revisions, but visitors see only the default version.
Revisions let you:
- Roll back to previous versions,
- Work with drafts without affecting the published version,
- Track content history.
Default Revision — The “Main” Version
The default revision is the version of content displayed to site visitors.
- Only one revision should be default at a time.
- Drupal ensures exactly one default revision exists per content item.
Example:
- Revision #5 — published (default).
- Revision #6 — draft (not default).
- Visitors still see Revision #5 while editing continues.
The Problem
Previously, Drupal allowed marking the current default revision as non-default without creating a new revision.
Example:
- Revision #10 — default.
- Administrator edits it and unchecks “Make this the default revision.”
- Result:
- Revision #10 is no longer default,
- No new default revision exists.
⚠️ Consequences:
- Views or API calls may return empty results,
- Cache or database may become inconsistent,
- Users may see incorrect content.
The Proposed Solution: Issue #3543212
Drupal.org issue #3543212 proposes:
- You cannot uncheck the default status of the current default revision.
- To change which revision is default, a new revision must be created.
Example of new behavior:
- Revision #12 — default.
- Editor saves content and indicates it should not be default.
- Drupal:
- Creates Revision #13,
- Marks it as default,
- Revision #12 remains in history but is no longer default.
Impact on Content Moderation
The Content Moderation module adds states like:
- Draft,
- Published,
- Archived.
Before the change:
- Admin could remove default from the published version → site could have no default revision.
After the change:
- Drupal guarantees at least one default revision always exists,
- Workflows become more predictable,
- Data integrity is maintained.
Why This Matters
- Predictable site behavior — users always see the correct published version.
- Data integrity — revision history remains consistent.
- Simpler development — developers can rely on one default revision.
- Reliable moderation workflows — drafts and published versions work smoothly.
Working with Revisions via Drupal API
Checking the Default Revision
use Drupal\node\Entity\Node;
$node = Node::load(123);
$default_revision_id = $node->getRevisionId();
if ($node->isDefaultRevision()) {
\Drupal::logger('custom')->info('This revision is default: ' . $default_revision_id);
} else {
\Drupal::logger('custom')->info('This revision is not default.');
}
Creating a New Revision
$node = Node::load(123);
// Create a new revision
$node->setNewRevision(TRUE);
// Update content
$node->setTitle('New Revision Title');
// Save as default revision
$node->setRevisionAsDefault(TRUE);
$node->save();
Listing All Revisions
$revision_ids = \Drupal::entityTypeManager()
->getStorage('node')
->revisionIds($node);
foreach ($revision_ids as $rid) {
$revision = Node::loadRevision($rid);
$status = $revision->isDefaultRevision() ? 'default' : 'non-default';
\Drupal::logger('custom')->info("Revision $rid — $status");
}
Working with Content Moderation
$node = Node::load(123);
// Create a draft revision
$node->setNewRevision(TRUE);
$node->set('moderation_state', 'draft');
$node->setRevisionAsDefault(FALSE);
$node->save();
// Publish a new revision
$node->setNewRevision(TRUE);
$node->set('moderation_state', 'published');
$node->setRevisionAsDefault(TRUE);
$node->save();
This ensures:
- One default revision is always published,
- Drafts can coexist,
- Data consistency is preserved.
Conclusion
The Drupal change #3543212 may seem minor, but it significantly improves system stability:
- Prevents losing default revisions,
- Maintains reliable workflows,
- Makes Content Moderation more predictable,
- Simplifies development and reduces errors.
If you use revisions and moderation workflows, this change is essential for safe and stable content management.
Comments