You are here

public function ContentImportForm::buildForm in Content Synchronization 8

Same name and namespace in other branches
  1. 8.2 src/Form/ContentImportForm.php \Drupal\content_sync\Form\ContentImportForm::buildForm()
  2. 3.0.x src/Form/ContentImportForm.php \Drupal\content_sync\Form\ContentImportForm::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/ContentImportForm.php, line 23

Class

ContentImportForm
Defines the content import form.

Namespace

Drupal\content_sync\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $directory = content_sync_get_content_directory('sync');
  $directory_is_writable = is_writable($directory);
  if (!$directory_is_writable) {
    $this
      ->logger('content_sync')
      ->error('The directory %directory is not writable.', [
      '%directory' => $directory,
      'link' => 'Import Archive',
    ]);
    drupal_set_message($this
      ->t('The directory %directory is not writable.', [
      '%directory' => $directory,
    ]), 'error');
  }
  $form['import_tarball'] = [
    '#type' => 'file',
    '#title' => $this
      ->t('Configuration archive'),
    '#description' => $this
      ->t('Allowed types: @extensions.', [
      '@extensions' => 'tar.gz tgz tar.bz2',
    ]),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Upload'),
    '#disabled' => !$directory_is_writable,
  ];
  return $form;
}