You are here

BackupMigrateRestoreForm.php in Backup and Migrate 8.4

Same filename and directory in other branches
  1. 5.0.x src/Form/BackupMigrateRestoreForm.php

File

src/Form/BackupMigrateRestoreForm.php
View source
<?php

namespace Drupal\backup_migrate\Form;

use BackupMigrate\Drupal\Config\DrupalConfigHelper;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Provides a form for performing a 1-click site backup.
 */
class BackupMigrateRestoreForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'backup_migrate_ui_manual_backup_quick';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = [];
    $bam = backup_migrate_get_service_object();
    $form['backup_migrate_restore_upload'] = [
      '#title' => $this
        ->t('Upload a Backup File'),
      '#type' => 'file',
      '#description' => $this
        ->t("Upload a backup file created by Backup\n      and Migrate. For other database or file backups please use another\n      tool for import. Max file size: %size", [
        "%size" => format_size(file_upload_max_size()),
      ]),
    ];
    $form['source_id'] = DrupalConfigHelper::getPluginSelector($bam
      ->sources(), $this
      ->t('Restore To'));
    $form += DrupalConfigHelper::buildAllPluginsForm($bam
      ->plugins(), 'restore');
    $form['quickbackup']['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Restore now'),
      '#weight' => 1,
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $form_state
      ->getValues();
    backup_migrate_perform_restore($config['source_id'], 'upload', 'backup_migrate_restore_upload', $config);
  }

}

Classes

Namesort descending Description
BackupMigrateRestoreForm Provides a form for performing a 1-click site backup.