Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

i18n_form_alter

Definition

i18n_form_alter(&$form, $form_state, $form_id)
contributions/i18n/i18n.module, line 432

Description

Implementation of hook_form_alter();

This is the place to add language fields to all forms

Code

<?php
function i18n_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id){
     case 'node_type_form':
       // Add extended language support option to content type form.
       $form['workflow']['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.')
       );

       break;

    default:
      // Extended language for node edit form
      if (isset($form['#id']) && $form['#id'] == 'node-form') {
        if (isset($form['#node']->type) && variable_get('language_content_type_'. $form['#node']->type, 0)) {
          $form['language']['#options'] = i18n_node_language_list($form['#node'], TRUE);
        }
      }
      /** @ TO DO Upgrade
      if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && $node = $form['#node']) {
        // Language field
        if(variable_get('i18n_node_'.$form['type']['#value'], 0) && !isset($form['i18n']['language'])) {
          // Language field
          $form['i18n'] = array('#type' => 'fieldset', '#title' => t('Multilingual settings'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#weight' => -4);
          // Language will default to current only when creating a node
          $language = isset($form['#node']->language) ? $form['#node']->language : (arg(1)=='add' ? i18n_get_lang() : '');
          $form['i18n']['language'] = _i18n_language_select($language, t('If you change the Language, you must click on <i>Preview</i> to get the right Categories &amp; Terms for that language.'), -4, i18n_node_language_list($node));
          $form['i18n']['trid'] = array('#type' => 'value', '#value' => $form['#node']->trid);
        }
        // Correction for lang/node/nid aliases generated by path module
        // if($form['#node']->path && $form['#node']->path == i18n_get_lang().'/node/'.$form['#node']->nid){
        if($node->path) {
          $alias = drupal_lookup_path('alias', 'node/'.$node->nid);
          if($alias && $alias != 'node/'.$node->nid){
            $form['#node']->path = $alias;
          } else {
            unset($form['#node']->path);
          }
        }
      }
      */
      // Multilingual variables in settings form
      if (isset($form['#theme']) && $form['#theme'] == 'system_settings_form' && $variables = variable_get('i18n_variables', 0)) {
        if (i18n_form_alter_settings($form, $variables)) {
          $form['#submit'][] = 'i18n_variable_form_submit';
        }
      }
  }    
}
?>