public function FileAddArchiveForm::buildForm in File Entity (fieldable files) 8.2
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 FormInterface::buildForm
File
- src/
Form/ FileAddArchiveForm.php, line 73
Class
- FileAddArchiveForm
- Form controller for archive type forms.
Namespace
Drupal\file_entity\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$options = [
'file_extensions' => $this->archiverManager
->getExtensions(),
];
$options = $form_state
->get('options') ? $form_state
->get('options') : $options;
$validators = $this
->getUploadValidators($options);
$form['upload'] = array(
'#type' => 'managed_file',
'#title' => $this
->t('Upload an archive file'),
'#upload_location' => 'public://',
'#progress_indicator' => 'bar',
'#default_value' => $form_state
->has('file') ? array(
$form_state
->get('file')
->id(),
) : NULL,
'#required' => TRUE,
'#description' => $this
->t('Files must be less than <strong>%valid_size</strong><br> Allowed file types: <strong>%valid_extension</strong>', array(
'%valid_size' => format_size($validators['file_validate_size'][0]),
'%valid_extension' => $validators['file_validate_extensions'][0],
)),
'#upload_validators' => $validators,
);
$form['pattern'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Pattern'),
'#description' => $this
->t('Only files matching this pattern will be imported. For example, to import all jpg and gif files, the pattern would be <strong>.*jpg|.*gif</strong>. Use <strong>.*</strong> to extract all files in the archive.'),
'#default_value' => '.*',
'#required' => TRUE,
);
$form['remove_archive'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Remove archive'),
'#description' => $this
->t('Removes archive after extraction.'),
'#default_value' => FALSE,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}