Drupal\node\Entity\NodeType wrong namespace for DRUPAL_OPTIONAL

Created on 24 February 2025, 12 days ago

Problem/Motivation

DRUPAL_OPTIONAL is defined in the system.module file.

Writing some Kernel tests, I found this error: Error: Undefined constant "Drupal\node\Entity\DRUPAL_OPTIONAL"

I eventually found the usage in \Drupal\node\Entity\NodeType, and when I temporarily modified it to say \DRUPAL_OPTIONAL, the error changed to: Error: Undefined constant "DRUPAL_OPTIONAL"

That's because it was a kernel test, and when I included the system module in my list of modules to add in the test, this error message went away (and was replaced by others, which is out of scope here... 😀)

When the system module is loaded, PHP eventually finds the correct constant in its namespace, but otherwise it's an error.

Also, this is a very minor issue to say the least, and brings our attention to 📌 Each class using DRUPAL_* constants from system.module should define its own constants Needs work where some refactoring is already underway.

But until that lands, this is still wrong and could maybe use some follow-through.

Steps to reproduce

Proposed resolution

Modify NodeType to include the \ namespace, like this:

protected $preview_mode = \DRUPAL_OPTIONAL;

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.1 🔥

Component

node system

Created by

🇺🇸United States mile23 Seattle, WA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024