I have a requirement where in hook_node_insert I need to get the language code of a field

What I have tried is

$langcode = $node->{$field_name}->langcode

But this returns null. Any suggestions?

And is it possible that different fields in a node have different langcode?

  • Use kint to explain $node, there you can find multiple functions to get lan code, must be a function getDefaultLanguage() or so. – harsh_behl_0007 Jan 9 at 10:51

You can use getLangcode
Try with:


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.