Skip to main content
Home
Drupal life hacks

Main navigation

  • Drupal
  • React
  • WP
  • Contact
  • About
User account menu
  • Log in

Breadcrumb

  1. Home

The Tale of the Retired Numbers in Drupal

By admin, 15 August, 2025

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 sees setPreviewMode(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.

Tags

  • #Drupal Planet

Comments

About text formats

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Powered by Drupal