Created
October 8, 2012 19:49
-
-
Save wojtha/3854528 to your computer and use it in GitHub Desktop.
Drupal 7: Return field value from multilanguage node fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return field value from multilanguage fields. | |
* | |
* The priority is following: | |
* 1. provided language, | |
* 2. node language, | |
* 3. undefined language | |
* | |
* @param $node | |
* @param $field | |
* @param null $langcode | |
* @return mixed | |
*/ | |
function _mymodule_get_field_value($node, $field, $langcode = NULL, $key = 'value') { | |
$value = NULL; | |
if ($langcode && isset($node->{$field}[$langcode][0][$key])) { | |
$value = $node->{$field}[$node->language][0][$key]; | |
} | |
elseif (isset($node->language, $node->{$field}[$node->language][0][$key])) { | |
$value = $node->{$field}[$node->language][0][$key]; | |
} | |
elseif (isset($node->{$field}[LANGUAGE_NONE][0][$key])) { | |
$value = $node->{$field}[LANGUAGE_NONE][0][$key]; | |
} | |
return $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment