You are here

protected function ReorderFolderForm::manage_folders_form in Taxonomy File Tree 8

Same name and namespace in other branches
  1. 3.x src/Form/ReorderFolderForm.php \Drupal\tft\Form\ReorderFolderForm::manage_folders_form()

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

Parameters

array $tree: The current tree level to be rendered.

mixed $form: A reference to the form array.

int $root_depth: The depth of the root term.

1 call to ReorderFolderForm::manage_folders_form()
ReorderFolderForm::buildForm in src/Form/ReorderFolderForm.php
Form constructor.

File

src/Form/ReorderFolderForm.php, line 25

Class

ReorderFolderForm
Term reordering form.

Namespace

Drupal\tft\Form

Code

protected function manage_folders_form(array $tree, &$form, $root_depth = 0) {
  foreach ($tree as $data) {
    $data['depth'] = isset($data['tid']) ? _tft_get_depth($data['tid']) - $root_depth : _tft_get_depth($data['parent']) - $root_depth + 1;
    $key = 'term-' . $data['tid'];
    $form['table'][$key] = [];
    $form['table'][$key]['name'] = [
      '#type' => 'textfield',
      '#default_value' => $data['name'],
      '#maxlength' => 255,
      '#required' => TRUE,
      '#size' => '',
    ];
    $form['table'][$key]['parent'] = [
      '#type' => 'textfield',
      '#default_value' => $data['parent'],
      '#size' => 6,
      '#attributes' => [
        'class' => [
          'taxonomy_term_hierarchy-parent',
        ],
      ],
    ];
    $form['table'][$key]['id'] = [
      '#type' => 'hidden',
      '#default_value' => $data['tid'],
      '#attributes' => [
        'class' => [
          'taxonomy_term_hierarchy-tid',
        ],
      ],
    ];
    $form['table'][$key]['type'] = [
      '#type' => 'hidden',
      '#value' => isset($data['type']) ? $data['type'] : 'term',
    ];
    $form['table'][$key]['depth'] = [
      '#type' => 'value',
      '#value' => $data['depth'],
    ];
    $form['table'][$key]['weight'] = [
      '#type' => 'weight',
      '#delta' => 50,
      '#default_value' => $data['weight'],
      '#attributes' => [
        'class' => [
          'taxonomy_term_hierarchy-weight',
        ],
      ],
    ];
    if (isset($data['children'])) {
      $this
        ->manage_folders_form($data['children'], $form, $root_depth);
    }
  }
}