Newer
Older
<?php
/**
* Implementation of hook_form_FORM_ID_alter
*/
function field_display_label_form_field_ui_field_edit_form_alter(&$form, $form_state, $form_id) {
$form['instance']['display_label'] = array(
'#type' => 'textfield',
'#title' => t('Display label'),
'#description' => t('A separate label for viewing this field. Leave blank to use the default field label.'),
'#default_value' => isset($form['#instance']['display_label']) ? $form['#instance']['display_label'] : '',
'#weight' => $form['instance']['label']['#weight'] + 1,
);
}
/**
* Implementation of hook_field_display_alter
*/
function field_display_label_theme_registry_alter(&$theme_registry) {
$theme_registry['field']['preprocess functions'][] = 'field_display_label_preprocess_field';
}
/**
* Preprocess function to replace the regular label with the display label
*/
function field_display_label_preprocess_field(&$variables) {
$field = field_info_instance($variables['element']['#entity_type'], $variables['element']['#field_name'], $variables['element']['#bundle']);
if (isset($field['display_label']) && strlen(trim($field['display_label'])) > 0) {
$variables['label'] = check_plain(i18n_field_translate_property($field, 'display_label'));
$variables['label'] = check_plain($field['display_label']);
}
}
}
/**
* Implementation of hook_i18n_object_info().
*/
function field_display_label_i18n_object_info_alter(&$info) {
if (!isset($info['field_instance'])) {
return;
$info['field_instance']['string translation']['properties']['display_label'] = t('Display label');
}