You are here

function theme_tft_manage_folders_form in Taxonomy File Tree 7

Same name and namespace in other branches
  1. 7.2 includes/tft.pages.inc \theme_tft_manage_folders_form()

Theme the term reordering form.

Parameters

array $form: The form

Return value

string The rendered form as HTML

See also

tft_manage_folders_form()

File

./tft.admin.inc, line 218

Code

function theme_tft_manage_folders_form($vars) {
  $form = $vars['form'];
  if ($form['#use_hierarchy']) {
    drupal_add_tabledrag('tft-outline', 'match', 'parent', 'taxonomy_term_hierarchy-parent', 'taxonomy_term_hierarchy-parent', 'taxonomy_term_hierarchy-tid');
  }
  if ($form['#use_weight']) {
    drupal_add_tabledrag('tft-outline', 'order', 'sibling', 'taxonomy_term_hierarchy-weight');
  }
  $header = array(
    t('Name'),
  );
  if ($form['#use_hierarchy']) {
    $header[] = t('Parent');
  }
  if ($form['#use_weight']) {
    $header[] = t('Weight');
  }
  $rows = array();
  foreach ($form['table'] as $key => $item) {
    if (is_array($item) && preg_match('/tft\\-admin\\-(node|term)-[0-9]+/', $key)) {
      $data = array();
      if ($item['type']['#value'] == 'term') {
        $path = drupal_get_path('module', 'tft') . '/img/folder.png';
      }
      else {
        $setting = tft_get_file_setting();
        $db_table = 'field_data_' . $setting['field'];
        $db_table = db_escape_field($db_table);
        $db_field = db_escape_field($setting['field'] . '_fid');
        $mime = db_query("SELECT f.filemime FROM {node_revision} v\n                            LEFT JOIN {node} n ON n.vid = v.vid\n                              LEFT JOIN {" . $db_table . "} c ON c.revision_id = v.vid\n                                LEFT JOIN {file_managed} f ON c.{$db_field} = f.fid\n                        WHERE n.nid = :nid", array(
          ':nid' => $item['id']['#default_value'],
        ))
          ->fetchField();
        $file = (object) array(
          'filemime' => $mime,
        );
        $path = file_icon_path($file);
      }
      $icon = theme('image', array(
        'path' => $path,
        'attributes' => array(
          'class' => array(
            'tft-admin-folder-content-item',
          ),
        ),
      ));
      $data[] = theme('indentation', array(
        'size' => isset($item['depth']['#value']) ? $item['depth']['#value'] : 0,
      )) . $icon . drupal_render($item['name']);
      if ($form['#use_hierarchy']) {
        $data[] = drupal_render($item['parent']) . drupal_render($item['id']) . drupal_render($item['type']);
      }
      if ($form['#use_weight']) {
        $data[] = drupal_render($item['weight']);
      }
      $row = array(
        'data' => $data,
      );
      if (isset($item['#attributes'])) {
        $row = array_merge($row, $item['#attributes']);
      }
      $row['class'][] = 'draggable' . ($item['type']['#value'] == 'node' ? ' tabledrag-leaf' : '');
      $rows[] = $row;
    }
  }
  $form['table'] = array(
    '#markup' => theme('table', array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'id' => 'tft-outline',
      ),
    )),
    '#weight' => 1,
  );
  return drupal_render_children($form);
}