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
- Determine why this is suddenly throwing an error. What changes about the handling of langcode in the language object?
- Make locale modules implementation of
locale_preprocess_node
.
Remaining tasks
- Write a test somewhere to codify this error.
- Fix the error.
User interface changes
none.
API changes
none.
Related Issues
none.