diff --git a/link.module b/link.module index d96391d..aad69e8 100644 --- a/link.module +++ b/link.module @@ -46,6 +46,7 @@ function link_field_info() { 'url' => 0, 'title' => 'optional', 'title_value' => '', + 'title_label_use_field_label' => FALSE, 'title_maxlength' => 128, 'enable_tokens' => 1, 'display' => array( @@ -107,6 +108,13 @@ function link_field_instance_settings_form($field, $instance) { '#description' => t('This title will always be used if “Static Title” is selected above.'), ); + $form['title_label_use_field_label'] = array( + '#type' => 'checkbox', + '#title' => t('Use field label as the label for the title field'), + '#default_value' => isset($instance['settings']['title_label_use_field_label']) ? $instance['settings']['title_label_use_field_label'] : FALSE, + '#description' => t('If this is checked the field label will be hidden.'), + ); + $form['title_maxlength'] = array( '#type' => 'textfield', '#title' => t('Max length of title field'), @@ -763,10 +771,21 @@ function link_field_process($element, $form_state, $complete_form) { '#default_value' => isset($element['#value']['url']) ? $element['#value']['url'] : NULL, ); if ($settings['title'] !== 'none' && $settings['title'] !== 'value') { + // Figure out the label of the title field. + if (!empty($settings['title_label_use_field_label'])) { + // Use the element label as the title field label. + $title_label = $element['#title']; + // Hide the field label because there is no need for the duplicate labels. + $element['#title_display'] = 'invisible'; + } + else { + $title_label = t('Title'); + } + $element['title'] = array( '#type' => 'textfield', '#maxlength' => $settings['title_maxlength'], - '#title' => t('Title'), + '#title' => $title_label, '#description' => t('The link title is limited to @maxlength characters maximum.', array('@maxlength' => $settings['title_maxlength'])), '#required' => ($settings['title'] == 'required' && (($element['#delta'] == 0 && $element['#required']) || !empty($element['#value']['url']))) ? TRUE : FALSE, '#default_value' => isset($element['#value']['title']) ? $element['#value']['title'] : NULL,