The Tale of the Retired Numbers in Drupal
Once upon a time in the cozy world of Drupal, there lived three humble numbers: 0, 1, and 2.
They had an important job — helping developers set the preview mode for content types.
- 0 — “No preview”
- 1 — “Preview optional”
- 2 — “Preview required”
For years, the numbers worked hard, faithfully serving Drupal projects everywhere.
But one day, a wise and modern newcomer appeared — NodePreviewMode.
He said:
“My friends, times are changing! Numbers aren’t always clear.
When a new developer seessetPreviewMode(1), they have no idea what it means.
Let’s give your roles real names so everyone can understand them instantly.”
The numbers were a little offended at first, but soon realized he was right.
From that day forward, instead of:
$node_type->setPreviewMode(1);
developers wrote:
use Drupal\node\NodePreviewMode;
$node_type->setPreviewMode(NodePreviewMode::Optional);
0 became NodePreviewMode::Disabled,
1 became NodePreviewMode::Optional,
2 became NodePreviewMode::Required.
Now, anyone looking at the code immediately understands what’s going on.
And the old numbers went into well-earned retirement, because in Drupal 13 they won’t exist anymore.
💡 Moral of the story:
Readable code isn’t just pretty — it saves time and sanity. If your project still uses numbers for preview mode, now’s the perfect time to meet NodePreviewMode.
Comments