You are here

public static function LocalizeFields::dateComboProcessAlter in Localize Fields 7

Translates Date fields' 'Field-name Start date' and 'Field-name End date' labels.

Used by hook_field_date_combo_process_alter() implementation.

Parameters

array &$element:

1 call to LocalizeFields::dateComboProcessAlter()
localize_fields_date_combo_process_alter in ./localize_fields.module
Translates 'Field Start date' and 'Field End date' labels.

File

./LocalizeFields.inc, line 692
Drupal Localize Fields module

Class

LocalizeFields
@file Drupal Localize Fields module

Code

public static function dateComboProcessAlter(&$element) {
  if (($localize = self::$localize) == -1) {

    // Save a method call if possible.
    $localize = self::localize();
  }
  if (!$localize) {
    return;
  }

  // The field label is already translated in another place - in the root of
  // $element.
  $filtered_translated_label = $element['#title'];
  $items = array(
    'value',
    'value2',
  );
  foreach ($items as $item) {
    if (array_key_exists($item, $element)) {

      // ['value']['#instance']['label']
      if (array_key_exists('#instance', $element[$item]) && array_key_exists('label', $element[$item]['#instance']) && ($source = $element[$item]['#instance']['label'])) {

        // The label on the row is not translated yet.
        $element[$item]['#instance']['label'] = $filtered_translated_label;

        // ['value']['#date_title'] is label + 'start date'|'end date'
        if (array_key_exists('#date_title', $element[$item]) && ($item_label = $element[$item]['#date_title']) && strpos($item_label, $source) !== FALSE) {
          $element[$item]['#date_title'] = field_filter_xss(str_replace($source, $filtered_translated_label, $item_label));
        }
      }
    }
  }
}