You are here

function tmgmt_field_get_source_data in Translation Management Tool 7

Helper function for retrieving all translatable field values from an entity.

Parameters

$entity_type: The entity type.

$entity: An entity object.

$langcode: The language of retrieved field values.

$only_translatable: If TRUE, only the fields which are flagged as translatable are returned. Defaults to FALSE, which is usually used for node translation, where the field translatability does not matter.

Return value

array The structured field data for all translatable fields

2 calls to tmgmt_field_get_source_data()
TMGMTEntitySourcePluginController::getData in sources/entity/tmgmt_entity.plugin.inc
Returns the data from the fields as a structure that can be processed by the Translation Management system.
TMGMTNodeSourcePluginController::getData in sources/node/tmgmt_node.plugin.inc
Returns the data from the fields as a structure that can be processed by the Translation Management system.

File

sources/field/tmgmt_field.module, line 61

Code

function tmgmt_field_get_source_data($entity_type, $entity, $langcode, $only_translatable = FALSE) {
  try {
    list(, , $bundle) = entity_extract_ids($entity_type, $entity);
  } catch (Exception $e) {
    watchdog_exception('tmgmt field', $e);
    return array();
  }
  $fields = array();
  foreach (field_info_instances($entity_type, $bundle) as $field_name => $instance) {
    $field = field_info_field($field_name);
    $items = field_get_items($entity_type, $entity, $field_name, $langcode);
    if ((!$only_translatable || $field['translatable']) && $items) {
      if ($data = module_invoke($field['module'], 'tmgmt_source_translation_structure', $entity_type, $entity, $field, $instance, $langcode, $items)) {
        $fields[$field_name] = $data;
      }
    }
  }
  drupal_alter('tmgmt_field_source_data', $fields, $entity_type, $entity, $langcode);
  return $fields;
}