You are here

function i18n_object_field in Internationalization 7

Get field value from object/array

6 calls to i18n_object_field()
i18n_object_key in ./i18n.module
Get key value from object/array
i18n_object_langcode in ./i18n.module
Get object language code
i18n_object_wrapper::get_field in ./i18n_object.inc
Get field value from object/array
i18n_string_translate_access in i18n_string/i18n_string.module
Check user access to translate a specific string.
i18n_taxonomy_vocabulary_mode in i18n_taxonomy/i18n_taxonomy.module
Taxonomy vocabulary settings.

... See full list

File

./i18n.module, line 456
Internationalization (i18n) module.

Code

function i18n_object_field($object, $field, $default = NULL) {
  if (is_array($field)) {

    // We can handle a list of fields too. This is useful for multiple keys (like blocks)
    foreach ($field as $key => $name) {
      $values[$key] = i18n_object_field($object, $name);
    }
    return $values;
  }
  elseif (strpos($field, '.')) {

    // Access nested properties with the form 'name1.name2..', will map to $object->name1->name2...
    $names = explode('.', $field);
    $current = array_shift($names);
    if ($nested = i18n_object_field($object, $current)) {
      return i18n_object_field($nested, implode('.', $names), $default);
    }
    else {
      return $default;
    }
  }
  elseif (is_object($object)) {
    return isset($object->{$field}) ? $object->{$field} : $default;
  }
  elseif (is_array($object)) {
    return isset($object[$field]) ? $object[$field] : $default;
  }
  else {
    return $default;
  }
}