You are here

function lingotek_normalize_field_collection_language in Lingotek Translation 7.4

2 calls to lingotek_normalize_field_collection_language()
lingotek_entity_load in ./lingotek.module
Implements hook_entity_load().
lingotek_entity_presave in ./lingotek.module
Implements hook_entity_presave().

File

./lingotek.module, line 1707

Code

function lingotek_normalize_field_collection_language($entity, $from_language_none = TRUE) {
  $host = lingotek_get_fc_parent($entity);
  if (!$host) {

    // unable to locate parent.  Abort.
    return;
  }
  $max_field_collection_depth = 10;

  // bubble up to the true parent to get its language,
  // which adds support for deeply nested entity collections
  for ($i = 0; $i < $max_field_collection_depth; $i++) {
    if ($host instanceof FieldCollectionItemEntity) {
      $host = lingotek_get_fc_parent($entity);
    }
  }
  foreach ($entity as $key => $value) {
    if (is_array($value) && array_key_exists(LANGUAGE_NONE, $value)) {
      if ($from_language_none) {
        $entity->{$key}[$host->language] = $value[LANGUAGE_NONE];
      }
      elseif (isset($value[$host->language])) {
        $entity->{$key}[LANGUAGE_NONE] = $value[$host->language];
      }
    }
  }
}