function template_preprocess_node
Same name and namespace in other branches
- 7.x modules/node/node.module \template_preprocess_node()
- 9 core/modules/node/node.module \template_preprocess_node()
- 10 core/modules/node/node.module \template_preprocess_node()
- 8.9.x core/modules/node/node.module \template_preprocess_node()
Prepares variables for node templates.
Default template: node.html.twig.
Most themes use their own copy of node.html.twig. The default is located inside "/core/modules/node/templates/node.html.twig". Look in there for the full list of variables.
By default this function performs special preprocessing of some base fields so they are available as variables in the template. For example 'title' appears as 'label'. This preprocessing is skipped if:
- a module makes the field's display configurable via the field UI by means of BaseFieldDefinition::setDisplayConfigurable()
- AND the additional entity type property 'enable_base_field_custom_preprocess_skipping' has been set using hook_entity_type_build().
Parameters
array $variables: An associative array containing:
- elements: An array of elements to display in view mode.
- node: The node object.
- view_mode: View mode; e.g., 'full', 'teaser', etc.
Deprecated
in drupal:11.3.0 and is removed from drupal:12.0.0. Use \Drupal::service(NodeThemeHooks::class)->preprocessNode($variables) instead.
See also
https://www.drupal.org/node/3533060
\Drupal\Core\Field\BaseFieldDefinition::setDisplayConfigurable()
File
-
core/
modules/ node/ node.module, line 264
Code
function template_preprocess_node(&$variables) : void {
@trigger_error(__FUNCTION__ . ' is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Use \\Drupal::service(NodeThemeHooks::class)->preprocessNode($variables); instead. See https://www.drupal.org/node/3533060', E_USER_DEPRECATED);
\Drupal::service(NodeThemeHooks::class)->preprocessNode($variables);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.