You are here

function i18n_form_alter in Internationalization 6

Same name and namespace in other branches
  1. 5.3 i18n.module \i18n_form_alter()
  2. 5 i18n.module \i18n_form_alter()
  3. 5.2 i18n.module \i18n_form_alter()

Implementation of hook_form_alter();

This is the place to add language fields to all forms.

File

./i18n.module, line 547
Internationalization (i18n) module.

Code

function i18n_form_alter(&$form, $form_state, $form_id) {
  global $language;
  switch ($form_id) {
    case 'node_type_form':
      $disabled = !variable_get('language_content_type_' . $form['#node_type']->type, 0);
      $form['i18n'] = array(
        '#type' => 'fieldset',
        '#title' => t('Multilanguage options'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#description' => t('Extended multilingual options provided by Internationalization module.'),
        '#disabled' => $disabled,
      );

      // Add disabled message
      if ($disabled) {
        $form['i18n']['#description'] .= ' <em>' . t('These will be available only when you enable Multilingual support in Workflow settings above.') . '</em>';
      }

      // Some settings about node languages
      $form['i18n']['options'] = array(
        '#title' => t('Options for node language'),
        '#type' => 'fieldset',
        '#disabled' => $disabled,
      );
      $form['i18n']['options']['i18n_newnode_current'] = array(
        '#type' => 'checkbox',
        '#title' => t('Set current language as default for new content.'),
        '#default_value' => variable_get('i18n_newnode_current_' . $form['#node_type']->type, 0),
        '#disabled' => $disabled,
      );
      $form['i18n']['options']['i18n_required_node'] = array(
        '#type' => 'checkbox',
        '#title' => t('Require language (Do not allow Language Neutral).'),
        '#default_value' => variable_get('i18n_required_node_' . $form['#node_type']->type, 0),
        '#disabled' => $disabled,
      );
      $form['i18n']['options']['i18n_lock_node'] = array(
        '#type' => 'checkbox',
        '#title' => t('Lock language (Cannot be changed).'),
        '#default_value' => variable_get('i18n_lock_node_' . $form['#node_type']->type, 0),
        '#disabled' => $disabled,
      );

      // Add extended language support option to content type form.
      $form['i18n']['i18n_node'] = array(
        '#type' => 'radios',
        '#title' => t('Extended language support'),
        '#default_value' => variable_get('i18n_node_' . $form['#node_type']->type, LANGUAGE_SUPPORT_NORMAL),
        '#options' => _i18n_content_language_options(),
        '#description' => t('If enabled, all defined languages will be allowed for this content type in addition to only enabled ones. This is useful to have more languages for content than for the interface.'),
        '#disabled' => $disabled,
      );
      break;
    default:

      // Extensions for node edit forms
      if (isset($form['#id']) && $form['#id'] == 'node-form') {
        if (isset($form['#node']->type)) {
          if (variable_get('language_content_type_' . $form['#node']->type, 0)) {
            if (!empty($form['language']['#options'])) {
              $form['language']['#options'] = i18n_node_language_list($form['#node'], TRUE);
            }
          }
          elseif (!isset($form['#node']->nid)) {

            // Set language to empty for not multilingual nodes when creating
            $form['language'] = array(
              '#type' => 'value',
              '#value' => '',
            );
          }
        }
      }

      // Multilingual variables in settings form.
      if (isset($form['#theme']) && $form['#theme'] == 'system_settings_form' && ($variables = i18n_variable())) {
        if ($i18n_variables = i18n_form_alter_settings($form, $variables)) {
          array_unshift($form['#submit'], 'i18n_variable_form_submit');
          $form['#i18n_variables'] = $i18n_variables;
        }
      }
  }
}