public function FileReplaceForm::form in File Replace (D8) 8
Gets the actual form array to be built.
Overrides ContentEntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ FileReplaceForm.php, line 33
Class
- FileReplaceForm
- Form controller for the file replace forms.
Namespace
Drupal\file_replace\FormCode
public function form(array $form, FormStateInterface $form_state) {
/** @var \Drupal\file\FileInterface $file */
$file = $this
->getEntity();
$form['original'] = [
'#type' => 'fieldset',
'#title' => t('Original'),
];
$form['original']['link'] = [
'#theme' => 'file_link',
'#file' => $file,
'#cache' => [
'tags' => $file
->getCacheTags(),
],
];
$extension = pathinfo($file
->getFileUri(), PATHINFO_EXTENSION);
$form['replacement'] = [
'#type' => 'fieldset',
'#title' => t('Replacement'),
];
$form['replacement']['replacement'] = [
'#type' => 'file',
'#description' => $this
->t('Select a file with extension .%extension and mimetype %mimetype to replace this file with.', [
'%extension' => $extension,
'%mimetype' => $file
->getMimeType(),
]),
'#upload_validators' => [
'file_validate_extensions' => [
$extension,
],
],
'#attributes' => [
'accept' => $file
->getMimeType(),
],
];
return parent::form($form, $form_state);
}