public function FileDeleteForm::buildForm in Ubercart 8.4
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfirmFormBase::buildForm
File
- uc_file/
src/ Form/ FileDeleteForm.php, line 60
Class
- FileDeleteForm
- Performs delete file action.
Namespace
Drupal\uc_file\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$file_ids = array_filter($form_state
->getValue('file_select'));
$form['file_ids'] = [
'#type' => 'value',
'#value' => $file_ids,
];
$form['action'] = [
'#type' => 'value',
'#value' => $form_state
->getValue([
'uc_file_action',
'action',
]),
];
$file_ids = _uc_file_sort_names(_uc_file_get_dir_file_ids($file_ids, FALSE));
$affected_list = $this
->buildJsFileDisplay($file_ids);
$has_directory = FALSE;
foreach ($file_ids as $file_id) {
// Gather a list of user-selected filenames.
$file = uc_file_get_by_id($file_id);
$filename = $file->filename;
$file_list[] = substr($filename, -1) == '/' ? $filename . ' (' . $this
->t('directory') . ')' : $filename;
// Determine if there are any directories in this list.
$path = uc_file_qualify_file($filename);
if (is_dir($path)) {
$has_directory = TRUE;
}
}
// Base files/dirs the user selected.
$form['selected_files'] = [
'#theme' => 'item_list',
'#items' => $file_list,
'#attributes' => [
'class' => [
'selected-file-name',
],
],
];
// Don't even show the recursion checkbox unless we have any directories.
if ($has_directory && $affected_list[TRUE] !== FALSE) {
$form['recurse_directories'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Delete selected directories and their sub directories'),
];
// Default to FALSE. Although we have the JS behavior to update with the
// state of the checkbox on load, this should improve the experience of
// users who don't have JS enabled over not defaulting to any info.
$form['affected_files'] = [
'#theme' => 'item_list',
'#items' => $affected_list[FALSE],
'#title' => $this
->t('Affected files'),
'#attributes' => [
'class' => [
'affected-file-name',
],
],
];
}
return parent::buildForm($form, $form_state);
}