public function FileEditForm::form in File Entity (fieldable files) 8.2
Gets the actual form array to be built.
Overrides ContentEntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
1 call to FileEditForm::form()
- FileInlineEditForm::form in src/
Form/ FileInlineEditForm.php - Gets the actual form array to be built.
1 method overrides FileEditForm::form()
- FileInlineEditForm::form in src/
Form/ FileInlineEditForm.php - Gets the actual form array to be built.
File
- src/
Form/ FileEditForm.php, line 63
Class
- FileEditForm
- Form controller for file type forms.
Namespace
Drupal\file_entity\FormCode
public function form(array $form, FormStateInterface $form_state) {
/** @var FileInterface $file */
$file = $this->entity;
if ($this->operation == 'edit') {
if ($file
->bundle() == 'undefined') {
$type = $this
->t('file');
}
else {
$type = FileType::load($file
->bundle())
->label();
}
$form['#title'] = $this
->t('<em>Edit @type</em> "@title"', array(
'@type' => $type,
'@title' => $file
->label(),
));
// Add a 'replace this file' upload field if the file is writeable.
if ($file
->isWritable()) {
// Set up replacement file validation.
$replacement_options = array();
// Replacement file must have the same extension as the original file.
$replacement_options['file_extensions'] = pathinfo($file
->getFilename(), PATHINFO_EXTENSION);
$form['replace_upload'] = array(
'#type' => 'managed_file',
'#title' => $this
->t('Replace file'),
'#upload_validators' => $this
->getUploadValidators($replacement_options),
);
$file_upload_help = array(
'#theme' => 'file_upload_help',
'#description' => $this
->t('This file will replace the existing file. This action cannot be undone.'),
'#upload_validators' => $form['replace_upload']['#upload_validators'],
);
$form['replace_upload']['#description'] = $this->renderer
->render($file_upload_help);
}
}
return parent::form($form, $form_state, $file);
}