You are here

function i18nsync_form_alter in Internationalization 5.2

Same name and namespace in other branches
  1. 5.3 experimental/i18nsync.module \i18nsync_form_alter()
  2. 5 experimental/i18nsync.module \i18nsync_form_alter()
  3. 6 i18nsync/i18nsync.module \i18nsync_form_alter()

Implementation of hook_form_alter().

File

experimental/i18nsync.module, line 19
Internationalization (i18n) package. Synchronization of translations

Code

function i18nsync_form_alter($form_id, &$form) {

  // Taxonomy vocabulary form
  switch ($form_id) {
    case 'taxonomy_form_vocabulary':
      $nodesync = variable_get('i18n_vocabulary_nodesync', array());
      $form['i18n']['nodesync'] = array(
        '#type' => 'checkbox',
        '#title' => t('Synchronize node translations'),
        '#default_value' => isset($form['vid']) && is_numeric($form['vid']['#value']) && $nodesync[$form['vid']['#value']],
        '#description' => t('Synchronize terms of this vocabulary for node translations.'),
      );
      break;
    case 'node_type_form':
      $type = isset($form['old_type']) && isset($form['old_type']['#value']) ? $form['old_type']['#value'] : NULL;
      $current = i18nsync_node_fields($type);
      $form['workflow']['i18n']['i18nsync_nodeapi'] = array(
        '#type' => 'fieldset',
        '#tree' => TRUE,
        '#title' => t('Synchronize translations'),
        '#collapsible' => TRUE,
        '#collapsed' => !count($current),
        '#description' => t('Select which fields to synchronize for all translations of this content type.'),
      );

      // Each set provides title and options. We build a big checkboxes control for it to be
      // saved as an array. Special themeing for group titles.
      foreach (i18nsync_node_available_fields($type) as $group => $data) {
        if (array_key_exists('#options', $data)) {
          $title = $data['#title'];
          foreach ($data['#options'] as $field => $name) {
            $form['workflow']['i18n']['i18nsync_nodeapi'][$field] = array(
              '#group_title' => $title,
              '#title' => $name,
              '#type' => 'checkbox',
              '#default_value' => in_array($field, $current),
              '#theme' => 'i18nsync_workflow_checkbox',
            );
            $title = '';
          }
        }
      }
      break;
  }
}