Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. locale.module

function locale_preprocess_node

Implements hook_preprocess_HOOK() for node templates.

File

core/modules/locale/locale.module, line 442

Code

function locale_preprocess_node(&$variables) : void {
    
    /** @var \Drupal\node\NodeInterface $node */
    $node = $variables['node'];
    if ($node->language()
        ->getId() != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
        $interface_language = \Drupal::languageManager()->getCurrentLanguage();
        $node_language = $node->language();
        if ($node_language->getId() != $interface_language->getId()) {
            // If the node language was different from the page language, we should
            // add markup to identify the language. Otherwise the page language is
            // inherited.
            $variables['attributes']['lang'] = $node_language->getId();
            if ($node_language->getDirection() != $interface_language->getDirection()) {
                // If text direction is different form the page's text direction, add
                // direction information as well.
                $variables['attributes']['dir'] = $node_language->getDirection();
            }
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal