You are here

function _tft_manage_folders_form in Taxonomy File Tree 7.2

Same name and namespace in other branches
  1. 7 tft.admin.inc \_tft_manage_folders_form()

Form helper. Flattens the terms tree and creates the form elements.

Parameters

array $tree:

array &$form:

int $root_depth = 0: The depth of the root term

int $root_tid = NULL: The root tid

See also

tft_manage_folders_form()

1 call to _tft_manage_folders_form()
tft_manage_folders_form in includes/tft.pages.inc
Form: reorganize folder items.

File

includes/tft.pages.inc, line 420
Defines all page callbacks for TFT.

Code

function _tft_manage_folders_form($tree, &$form, $root_depth = 0, $root_tid = NULL) {
  if (!isset($form['#use_weight'])) {
    $form['#use_weight'] = variable_get('tft_use_weight', 0);
  }
  foreach ($tree as $data) {

    // @todo OG logic !
    if ($root_tid && isset($data['tid']) && $data['tid'] == tft_get_archive_tid($root_tid)) {
      continue;
    }
    $data['depth'] = isset($data['tid']) ? tft_get_depth($data['tid']) - $root_depth : tft_get_depth($data['parent']) - $root_depth + 1;
    $key = 'tft-admin-' . (isset($data['nid']) ? 'node-' . $data['nid'] : 'term-' . $data['tid']);
    $form['table'][$key] = array();
    $form['table'][$key]['name'] = array(
      '#type' => 'textfield',
      '#default_value' => $data['name'],
      '#maxlength' => 255,
      '#required' => TRUE,
    );
    if (isset($data['type']) && $data['type'] == 'node') {
      $form['table'][$key]['name']['#required'] = FALSE;
      $form['table'][$key]['name']['#attributes'] = array(
        'disabled' => 'disabled',
      );
    }
    $form['table'][$key]['parent'] = array(
      '#type' => 'textfield',
      '#default_value' => $data['parent'],
      '#size' => 6,
      '#attributes' => array(
        'class' => array(
          'taxonomy_term_hierarchy-parent',
        ),
      ),
    );
    $form['table'][$key]['id'] = array(
      '#type' => 'hidden',
      '#default_value' => isset($data['nid']) ? $data['nid'] : $data['tid'],
      '#attributes' => array(
        'class' => array(
          'taxonomy_term_hierarchy-' . (isset($data['nid']) ? 'nid' : 'tid'),
        ),
      ),
    );
    $form['table'][$key]['type'] = array(
      '#type' => 'hidden',
      '#value' => isset($data['type']) ? $data['type'] : 'term',
    );
    $form['table'][$key]['depth'] = array(
      '#type' => 'value',
      '#value' => $data['depth'],
    );
    if ($form['#use_weight']) {
      $form['table'][$key]['weight'] = array(
        '#type' => 'weight',
        '#delta' => 50,
        '#default_value' => $data['weight'],
        '#attributes' => array(
          'class' => array(
            'taxonomy_term_hierarchy-weight',
          ),
        ),
      );
    }
    if (isset($data['children'])) {
      _tft_manage_folders_form($data['children'], $form, $root_depth, $root_tid);
    }
  }
}