You are here

public function BackupMigrateAdvancedBackupForm::buildForm in Backup and Migrate 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Form/BackupMigrateAdvancedBackupForm.php \Drupal\backup_migrate\Form\BackupMigrateAdvancedBackupForm::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/BackupMigrateAdvancedBackupForm.php, line 24

Class

BackupMigrateAdvancedBackupForm
Provides a form for performing a 1-click site backup.

Namespace

Drupal\backup_migrate\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Leave a message about the Entire Site backup.
  // @see https://www.drupal.org/project/backup_migrate/issues/3151290
  $this
    ->messenger()
    ->addMessage($this
    ->t('It is recommended to not use the "Entire site" backup as it has a tendency of failing on anything but the tiniest of sites. Hopefully this will be fixed in a future release.'));
  $form = [];

  // Theme the form if we want it inline.
  // @FIXME
  // $form['#theme'] = 'backup_migrate_ui_manual_quick_backup_form_inline';
  $bam = backup_migrate_get_service_object();
  $form['source'] = [
    '#type' => 'fieldset',
    "#title" => $this
      ->t("Source"),
    "#collapsible" => TRUE,
    "#collapsed" => FALSE,
    "#tree" => FALSE,
  ];
  $form['source']['source_id'] = DrupalConfigHelper::getSourceSelector($bam, $this
    ->t('Backup Source'));
  $form['source']['source_id']['#default_value'] = \Drupal::config('backup_migrate.settings')
    ->get('backup_migrate_source_id');
  $form += DrupalConfigHelper::buildAllPluginsForm($bam
    ->plugins(), 'backup');
  if (\Drupal::moduleHandler()
    ->moduleExists('token')) {
    $filename_token = [
      '#theme' => 'token_tree_link',
      '#token_types' => [
        'site',
      ],
      '#dialog' => TRUE,
      '#click_insert' => TRUE,
      '#show_restricted' => TRUE,
      '#group' => 'file',
    ];
  }
  else {
    $filename_token = [
      '#type' => 'markup',
      '#markup' => 'In order to use tokens for File Name, please install & enable <a href="https://www.drupal.org/project/token" arget="_blank">Token module</a>. <p></p>',
    ];
  }
  array_splice($form['file'], 4, 0, [
    'filename_token' => $filename_token,
  ]);
  $form['destination'] = [
    '#type' => 'fieldset',
    "#title" => $this
      ->t("Destination"),
    "#collapsible" => TRUE,
    "#collapsed" => FALSE,
    "#tree" => FALSE,
  ];
  $form['destination']['destination_id'] = DrupalConfigHelper::getDestinationSelector($bam, $this
    ->t('Backup Destination'));
  $form['destination']['destination_id']['#default_value'] = \Drupal::config('backup_migrate.settings')
    ->get('backup_migrate_destination_id');
  $form['quickbackup']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Backup now'),
    '#weight' => 1,
  ];
  return $form;
}