function i18n_field_field_attach_form in Internationalization 7
Implements hook_field_attach_form().
After the form fields are built. Translate title and description for fields with multiple values.
File
- i18n_field/
i18n_field.module, line 95 - Internationalization (i18n) module - Field handling
Code
function i18n_field_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
// Determine the list of instances to iterate on.
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
$instances = field_info_instances($entity_type, $bundle);
foreach ($instances as $field_name => $instance) {
if (isset($form[$field_name])) {
$langcode = $form[$field_name]['#language'];
$field =& $form[$field_name];
// Note: cardinality for unlimited fields is -1
if (isset($field[$langcode]['#cardinality']) && $field[$langcode]['#cardinality'] != 1) {
$translated = i18n_string_object_translate('field_instance', $instance);
if (!empty($field[$langcode]['#title'])) {
$field[$langcode]['#title'] = $translated['label'];
}
if (!empty($field[$langcode]['#description'])) {
$field[$langcode]['#description'] = $translated['description'];
}
}
}
}
}