You are here

function FileAddForm::stepUpload in File Entity (fieldable files) 8.2

Step 1 Generate form fields for the first step in the add file wizard.

Parameters

array $form: Holds form data

FormStateInterface $form_state: Holds form state data

Return value

array Returns form data

1 call to FileAddForm::stepUpload()
FileAddForm::buildForm in src/Form/FileAddForm.php
Form constructor.

File

src/Form/FileAddForm.php, line 126

Class

FileAddForm
Form controller for file type forms.

Namespace

Drupal\file_entity\Form

Code

function stepUpload(array $form, FormStateInterface $form_state) {
  $options = [
    'file_extensions' => \Drupal::config('file_entity.settings')
      ->get('default_allowed_extensions'),
  ];
  $options = $form_state
    ->get('options') ? $form_state
    ->get('options') : $options;
  $validators = $this
    ->getUploadValidators($options);
  $form['upload'] = array(
    '#type' => 'managed_file',
    '#title' => t('Upload a new file'),
    '#upload_location' => $this
      ->getUploadDestinationUri($form_state
      ->get('options')),
    '#upload_validators' => $validators,
    '#progress_indicator' => 'bar',
    '#required' => TRUE,
    '#default_value' => $form_state
      ->has('file') ? array(
      $form_state
        ->get('file')
        ->id(),
    ) : NULL,
  );
  $file_upload_help = array(
    '#theme' => 'file_upload_help',
    '#upload_validators' => $form['upload']['#upload_validators'],
  );
  $form['upload']['#description'] = $this->renderer
    ->render($file_upload_help);
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['next'] = array(
    '#type' => 'submit',
    '#button_type' => 'primary',
    '#value' => t('Next'),
  );
  return $form;
}