You are here

public function CmisBrowserDocumentUploadForm::buildForm in CMIS API 8.2

Same name and namespace in other branches
  1. 8 src/Form/CmisBrowserDocumentUploadForm.php \Drupal\cmis\Form\CmisBrowserDocumentUploadForm::buildForm()
  2. 3.0.x src/Form/CmisBrowserDocumentUploadForm.php \Drupal\cmis\Form\CmisBrowserDocumentUploadForm::buildForm()

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/CmisBrowserDocumentUploadForm.php, line 55

Class

CmisBrowserDocumentUploadForm
Provides a form to upload documents.

Namespace

Drupal\cmis\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) : array {
  $directory = $this->fileSystem
    ->getTempDirectory();
  $config = $this
    ->getRouteMatch()
    ->getParameter('config');
  $this->cmisConnectionApi
    ->checkConnectionIsAlive($config, TRUE);
  $directory_is_writable = is_writable($directory);
  if (!$directory_is_writable) {
    $this
      ->messenger()
      ->addError($this
      ->t('The directory %directory is not writable.', [
      '%directory' => $directory,
    ]));
  }
  $form['local_file'] = [
    '#type' => 'file',
    '#title' => $this
      ->t('Local file'),
    '#description' => $this
      ->t('Choose the local file to uploading'),
  ];
  $form['description'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Document description'),
    '#description' => $this
      ->t('Enter the document description'),
    '#default_value' => $form_state
      ->getValue('description'),
  ];
  $form['config'] = [
    '#type' => 'hidden',
    '#default_value' => $config,
  ];
  $form['folder_id'] = [
    '#type' => 'hidden',
    '#default_value' => $this
      ->getRouteMatch()
      ->getParameter('folder_id'),
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Upload'),
  ];
  return $form;
}