Skip to content

Instantly share code, notes, and snippets.

@vkechagias
Last active January 15, 2019 14:23
Show Gist options
  • Save vkechagias/c0fe26cceb8c807a307fb7693c8450aa to your computer and use it in GitHub Desktop.
Save vkechagias/c0fe26cceb8c807a307fb7693c8450aa to your computer and use it in GitHub Desktop.
Drupal 8: Proper way to consistently get field entity according to active language in themename.theme
function THEME_preprocess_page__node(&$variables) {
$translated_node = \Drupal::service('entity.repository')->getTranslationFromContext($variables['node']);
if (!empty($translated_node)) {
$field_data = $translated_node->get('FIELD_MACHINE_NAME')->getValue();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment