Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295366

Error notice in locale modules implementation of hook_preprocess_HOOK

$
0
0

Problem/Motivation

After enabling the locale module (8.x:4ac864574567c9cf8c32b5740a2d7a1112a99bf1), A series of errors are thrown, copied below:

Notice: Trying to get property of non-object in locale_preprocess_node() (line 879 of core/modules/locale/locale.module).
Notice: Trying to get property of non-object in locale_preprocess_node() (line 884 of core/modules/locale/locale.module).

The function responsible for the errors in locale_preprocess_node:

function locale_preprocess_node(&$variables) {
  if ($variables['node']->langcode != Language::LANGCODE_NOT_SPECIFIED) {
    $language_interface = language(Language::TYPE_INTERFACE);

    $node_language = language_load($variables['node']->langcode);
    if ($node_language->id != $language_interface->id) {
      // 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'] = $variables['node']->langcode;
      if ($node_language->direction != $language_interface->direction) {
        // If text direction is different form the page's text direction, add
        // direction information as well.
        $dir = array('ltr', 'rtl');
        $variables['attributes']['dir'] = $dir[$node_language->direction];
      }
    }
  }
}

the language_load function in bootstrap.inc has the potential to return null.

/**
* Loads a language object from the database.
*
* @param string $langcode
*   The language code.
*
* @return \Drupal\core\Language\Language|null
*   A fully-populated language object or NULL.
*/
function language_load($langcode) {
  $languages = language_list(Language::STATE_ALL);
  return isset($languages[$langcode]) ? $languages[$langcode] : NULL;
}

But the locale module does not take this into account.

Proposed resolution

  1. Determine why this is suddenly throwing an error. What changes about the handling of langcode in the language object?
  2. Make locale modules implementation of locale_preprocess_node.

Remaining tasks

  1. Write a test somewhere to codify this error.
  2. Fix the error.

User interface changes

none.

API changes

none.

none.

Original report by jessebeach


Viewing all articles
Browse latest Browse all 295366

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>