You are here

function finder_ui_i18n_string_map in Finder 7.2

Get a default map of which fields are translatable from the form.

2 calls to finder_ui_i18n_string_map()
finder_ui_finder_delete in modules/finder_ui/finder_ui.i18n_string.inc
Implements hook_finder_delete().
finder_ui_finder_presave in modules/finder_ui/finder_ui.i18n_string.inc
Implements hook_finder_presave().

File

modules/finder_ui/finder_ui.i18n_string.inc, line 69
i18n_string.inc

Code

function finder_ui_i18n_string_map($object, $form = NULL, $id = NULL, $parents = array()) {
  $map = array();
  if (is_null($form)) {
    if (empty($object->name)) {
      finder_inc('element', 'finder_ui');
      if (!is_object($object->finder)) {
        $object->finder = finder_load($object->finder);
      }
      $data = finder_ui_element($object->finder, $object->id);

      // Uses a '.' instead of ':' to prevent collisions between properties and element ids.
      $id = 'finder:' . $object->finder->name . '.' . $object->id . ':';
      $map['title'] = $id . 'title';
    }
    else {
      finder_inc('finder', 'finder_ui');
      $data = finder_ui($object);
      $id = 'finder:' . $object->name . ':';
      $map['title'] = $id . 'title';
      $map['description'] = $id . 'description';
    }
    $form = array();
    foreach ($data['items'] as $item) {
      foreach ($item['#form'] as $form_key => $form_item) {
        if (empty($form[$form_key])) {
          $form[$form_key] = array();
        }
        $form[$form_key] = array_merge($form[$form_key], $form_item);
      }
    }
  }
  foreach (element_children($form) as $key) {
    $path = $parents;
    $path[] = $key;

    // Set #translatable to true on these form element types, unless it is already set.
    if (!isset($form[$key]['#translatable']) && !empty($form[$key]['#type']) && in_array($form[$key]['#type'], array(
      'textfield',
      'textarea',
      'text_format',
    ))) {
      $form[$key]['#translatable'] = TRUE;
    }
    if (!empty($form[$key]['#translatable'])) {
      $map[$key] = $id . implode('.', $path);
    }
    $children = finder_ui_i18n_string_map($object, $form[$key], $id, $path);
    if (!empty($children)) {
      if (empty($map[$key])) {
        $map[$key] = array();
      }
      foreach ($children as $child_key => $child) {
        $map[$key][$child_key] = $child;
      }
    }
  }
  return $map;
}