Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By tim.plunkett on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
In Drupal 7, the node_add() function would take the machine name, for example:
module_load_include('inc', 'node', 'node.pages');
node_add('article');
However, node_add() is used only as a menu callback, and never called directly.
If you needed to do so, you would do this:
module_load_include('inc', 'node', 'node.pages');
node_add(node_type_load('article'));
In Drupal 8, it expects a fully loaded node type object. This is done automatically with the menu loader:
$items['node/add/%node_type'] = array(
'title callback' => 'node_type_get_clean_name',
'title arguments' => array(2),
'page callback' => 'node_add',
'page arguments' => array(2),
'access callback' => 'node_access',
'access arguments' => array('create', 2),
'description callback' => 'node_type_get_description',
'description arguments' => array(2),
'file' => 'node.pages.inc',
);
which calls node_type_load().
Also node_type_get_description() and node_type_get_clean_name() have been added as helper functions.
Impacts:
Module developers