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 Berdir on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
In Drupal 7 and earlier, hook_node_load() received an additional argument with a list of node types that $nodes contained. Modules that only wanted to change specific node types could check that and stop processing early.
This resulted in a fair bit of additional complexity when invoking that hook, in most cases more code as it was necessary to check both $types and $nodes and did not provide a measurable performance improvement.
The argument and the ability to specify these arguments for an entity type have been dropped.
7.x
function mymodule_node_load($nodes, $types) {
if (!in_array('my_node_type', $types)) {
return;
}
foreach ($nodes as $node) {
if ($node->type == 'my_node_type') {
// Do something.
}
}
}
8.x
function mymodule_node_load($nodes) {
foreach ($nodes as $node) {
if ($node->getType() == 'my_node_type') {
// Do something.
}
}
}
Impacts:
Module developers