You are here

function tft_form_alter in Taxonomy File Tree 7

Same name and namespace in other branches
  1. 8 tft.module \tft_form_alter()
  2. 7.2 tft.module \tft_form_alter()
  3. 3.x tft.module \tft_form_alter()

Implementation of hook_form_alter()

File

./tft.module, line 338
Module hooks.

Code

function tft_form_alter(&$form, &$form_state, $form_id) {
  $setting = tft_get_file_setting();
  switch ($form_id) {
    case $setting['type'] . '_node_form':
      $path = drupal_get_path('module', 'tft');
      drupal_add_js("{$path}/js/tft.select-folder.js");
      drupal_add_css("{$path}/css/tft.css");
      module_load_include('inc', 'tft', 'tft.pages');
      $form['tft_folder'][LANGUAGE_NONE]['#prefix'] = '<div class="tft-hide-element">' . (!empty($form['tft_folder'][LANGUAGE_NONE]['#prefix']) ? $form['tft_folder'][LANGUAGE_NONE]['#prefix'] : '');
      $form['tft_folder'][LANGUAGE_NONE]['#suffix'] .= '</div>';
      $form['og_group_ref'][LANGUAGE_NONE]['#prefix'] = '<div class="tft-hide-element">' . (!empty($form['og_group_ref'][LANGUAGE_NONE]['#prefix']) ? $form['og_group_ref'][LANGUAGE_NONE]['#prefix'] : '');
      $form['og_group_ref'][LANGUAGE_NONE]['#suffix'] .= '</div>';
      $form['tft_select_folder'] = array(
        '#type' => 'fieldset',
        '#title' => t("Select folder"),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
      );
      if (isset($_GET['gids'])) {
        $gid = trim($_GET['gids'][0]);
      }
      elseif (isset($form['#node']->og_groups) && count($form['#node']->og_groups)) {
        $gid = reset($form['#node']->og_groups);
      }
      if (!empty($gid)) {
        $top_tid = db_select('tft_tid_og_nid', 't')
          ->fields('t', array(
          'tid',
        ))
          ->condition('og_nid', $gid)
          ->execute()
          ->fetchField();
        $top_tid = $top_tid ? $top_tid : 0;
      }
      else {
        $top_tid = 0;
      }
      if (isset($_GET['tid'])) {
        $tid = $_GET['tid'];
      }
      elseif (isset($form['#node']->tft_folder[LANGUAGE_NONE][0]['tid'])) {
        $tid = $form['#node']->tft_folder[LANGUAGE_NONE][0]['tid'];
      }
      $tid = !empty($tid) ? $tid : 0;

      // If the user can only add terms to an OG term

      /*if (!user_access(TFT_ADD_TERMS)) {
          if (!tft_term_access($tid)) {
            drupal_set_message(t("You must select a parent folder that is part of a group you're a member of."), 'error');
          }
        }*/
      $og_tid = tft_get_og_tid(tft_get_og_nid($tid));
      $form['tft_select_folder']['tft_js_folder'] = array(
        '#markup' => '<div id="folder-explorer-container" class="tft-node-form">' . tft_output_tree(tft_folder_tree($og_tid, TRUE)) . '</div>',
      );
      $form['tft_selected_folder'] = array(
        '#type' => 'hidden',
        '#default_value' => $tid,
      );
      $form['#validate'][] = 'tft_file_node_validate';
      break;
  }
}