function translation_form_alter

6.x translation.module translation_form_alter(&$form, $form_state, $form_id)

Implementation of hook_form_alter().

  • Add translation option to content type form.
  • Alters language fields on node forms when a translation is about to be created.

File

drupal-6.x/modules/translation/translation.module, line 95
Manages content translations.

Code

function translation_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'node_type_form') {
    // Add translation option to content type form.
    $form['workflow']['language_content_type']['#options'][TRANSLATION_ENABLED] = t('Enabled, with translation');
    // Description based on text from locale.module.
    $form['workflow']['language_content_type']['#description'] = t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. You can also turn on translation for this content type, which lets you have content translated to any of the enabled languages. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/settings/language')));
  }
  elseif (isset($form['#id']) && $form['#id'] == 'node-form' && translation_supported_type($form['#node']->type)) {
    $node = $form['#node'];
    if (!empty($node->translation_source)) {
      // We are creating a translation. Add values and lock language field.
      $form['translation_source'] = array('#type' => 'value', '#value' => $node->translation_source);
      $form['language']['#disabled'] = TRUE;
    }
    elseif (!empty($node->nid) && !empty($node->tnid)) {
      // Disable languages for existing translations, so it is not possible to switch this
      // node to some language which is already in the translation set. Also remove the
      // language neutral option.
      unset($form['language']['#options']['']);
      foreach (translation_node_get_translations($node->tnid) as $translation) {
        if ($translation->nid != $node->nid) {
          unset($form['language']['#options'][$translation->language]);
        }
      }
      // Add translation values and workflow options.
      $form['tnid'] = array('#type' => 'value', '#value' => $node->tnid);
      $form['translation'] = array(
        '#type' => 'fieldset',
        '#title' => t('Translation settings'),
        '#access' => user_access('translate content'),
        '#collapsible' => TRUE,
        '#collapsed' => !$node->translate,
        '#tree' => TRUE,
        '#weight' => 30,
      );
      if ($node->tnid == $node->nid) {
        // This is the source node of the translation
        $form['translation']['retranslate'] = array(
          '#type' => 'checkbox',
          '#title' => t('Flag translations as outdated'),
          '#default_value' => 0,
          '#description' => t('If you made a significant change, which means translations should be updated, you can flag all translations of this post as outdated. This will not change any other property of those posts, like whether they are published or not.'),
        );
        $form['translation']['status'] = array('#type' => 'value', '#value' => 0);
      }
      else {
        $form['translation']['status'] = array(
          '#type' => 'checkbox',
          '#title' => t('This translation needs to be updated'),
          '#default_value' => $node->translate,
          '#description' => t('When this option is checked, this translation needs to be updated because the source post has changed. Uncheck when the translation is up to date again.'),
        );
      }
    }
  }
}