Skip to content

Instantly share code, notes, and snippets.

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