public function ActionForm::buildForm in Filebrowser 3.x
Same name and namespace in other branches
- 8.2 src/Form/ActionForm.php \Drupal\filebrowser\Form\ActionForm::buildForm()
Parameters
array $params: Array with filebrowser data keyed: 'header': the header to build the table select 'rows' : array of file info to display 'actions': Form actions that are allowed for current user 'dbFileList': all the ifo about the files:
Overrides FormInterface::buildForm
File
- src/
Form/ ActionForm.php, line 77
Class
- ActionForm
- Class ActionForm.
Namespace
Drupal\filebrowser\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $params = null) {
/** @var NodeInterface $node */
$this->error = false;
$node = $params['node'];
$actions = $params['actions'];
$this->nid = $node
->id();
$this->relativeFid = empty($params['dbFileList']['data']['fid']) ? 0 : $params['dbFileList']['data']['fid'];
$this->common = \Drupal::service('filebrowser.common');
$this->helper = \Drupal::service('form.helper');
// Initiate the form according default filebrowser requirements
$form = [];
$this->helper
->initForm($form, $node);
// Create the form action button and links (Upload, Rename etc.)
$this->helper
->createActionBar($form, $actions, $this->relativeFid);
// prepare the $rows array for $options
$options = [];
foreach ($params['rows'] as $row) {
$fid = $row['fid'];
unset($row['fid']);
foreach ($row as $key => $value) {
$options[$fid][$key] = [
'data' => $value,
];
}
}
$form['table'] = [
'#type' => 'tableselect',
'#tableselect' => true,
'#header' => $params['header'],
'#options' => $params['rows'],
'#multiple' => TRUE,
'#empty' => $this
->t('This directory is empty.'),
];
// search $options array to find the "Up Dir" line and de-activate the checkbox
foreach ($params['rows'] as $key => $option) {
if (empty($option['fid'])) {
$form['table'][$key]['#disabled'] = true;
}
}
return $form;
}