function tft_form_alter in Taxonomy File Tree 8
Same name and namespace in other branches
- 7.2 tft.module \tft_form_alter()
- 7 tft.module \tft_form_alter()
- 3.x tft.module \tft_form_alter()
Implements hook_form_alter().
File
- ./
tft.module, line 471 - Contains tft.module.
Code
function tft_form_alter(&$form, $form_state, $form_id) {
if ($form_id === 'media_tft_file_add_form' || $form_id === 'media_tft_file_edit_form') {
$tid = \Drupal::request()->query
->get('tid');
if (!$tid) {
$tid = 0;
}
$term = Term::load($tid);
if ($term) {
// Set the default folder based off the tid query param.
$form['tft_folder']['widget']['#default_value'] = $tid;
}
$form['tft_folder']['#attributes']['class'][] = 'tft-hide-element';
$form['tft_select_folder'] = [
'#type' => 'fieldset',
'#title' => t("Select folder"),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => $form['tft_folder']['#weight'],
];
$form['tft_select_folder']['tft_js_folder'] = [
'#type' => 'container',
'#attributes' => [
'id' => 'folder-explorer-container',
'class' => 'tft-node-form',
],
_tft_output_tree(_tft_folder_tree($tid, TRUE)),
];
$form['#attached']['library'][] = 'tft/tft.select-folder';
}
}