You are here

function i18n_access_form_alter in Translation Access 7

Same name and namespace in other branches
  1. 6 i18n_access.module \i18n_access_form_alter()

Implements hook_form_alter().

File

./i18n_access.module, line 126
file_description

Code

function i18n_access_form_alter(&$form, &$form_state, $form_id) {

  //Configuring translation edit form to limit it to allowed language
  if ($form_id == 'i18n_node_select_translation' && !user_access('administer nodes')) {
    $perms = i18n_access_load_permissions();
    foreach ($form['translations']['nid'] as $language => $translation) {
      if (!isset($perms[$language]) && $language != '#tree') {
        unset($form['translations']['nid'][$language]);
      }
    }
    foreach ($form['translations']['language'] as $language => $translation) {
      if (!isset($perms[$language]) && $language != '#tree') {
        unset($form['translations']['language'][$language]);
      }
    }
    foreach ($form['translations']['node'] as $language => $translation) {
      if (!isset($perms[$language]) && $language != '#tree') {
        unset($form['translations']['node'][$language]);
      }
    }
  }

  // Add i18n_access things to user/edit /user/add
  if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
    $form['i18n_access'] = array(
      '#type' => 'fieldset',
      '#title' => t('Translation access'),
      '#tree' => 0,
      '#access' => user_access('administer users'),
    );
    $form['i18n_access']['i18n_access'] = array(
      '#type' => 'checkboxes',
      '#options' => array(
        I18N_ACCESS_LANGUAGE_NEUTRAL => t('Language neutral'),
      ) + locale_language_list('name'),
      '#default_value' => i18n_access_load_permissions($form['#user']->uid),
      '#description' => t('Select the languages that this user should have permission to create and edit content for.'),
    );
  }
}