Skip to content

Instantly share code, notes, and snippets.

@vkechagias
Last active January 15, 2019 14:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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