You are here

public function BackupDatabaseSettingsForm::buildForm in Backup Database 8

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 ConfigFormBase::buildForm

File

src/Form/BackupDatabaseSettingsForm.php, line 37
Contains \Drupal\backup_db\Form\BackupDatabaseSettingsForm.

Class

BackupDatabaseSettingsForm
BackupDatabaseSettingsForm class.

Namespace

Drupal\backup_db\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('backup_db.settings');

  // general
  $form['path'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Path'),
    '#description' => $this
      ->t('The path database backups are saved to, should be a URI.'),
    '#default_value' => $config
      ->get('path'),
  );
  $date_types = DateFormat::loadMultiple();
  $date_formatter = \Drupal::service('date.formatter');
  $date_format_options = array();
  foreach ($date_types as $machine_name => $format) {
    $date_format_options[$machine_name] = t('@name - @sample', array(
      '@name' => $format
        ->label(),
      '@sample' => $date_formatter
        ->format(REQUEST_TIME, $machine_name),
    ));
  }
  $form['date'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Date format'),
    '#options' => $date_format_options,
    '#description' => $this
      ->t('Creates sub folders inside path with date format name.'),
    '#default_value' => $config
      ->get('date'),
  );

  // mysqldump settings
  $form['compress'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Compress'),
    '#options' => array(
      'None' => $this
        ->t('None'),
      'Gzip' => 'Gzip',
      'Bzip2' => 'Bzip2',
    ),
    '#description' => $this
      ->t('Compress the database export.'),
    '#default_value' => $config
      ->get('settings.compress'),
  );
  $form['no_data'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('No data'),
    '#description' => $this
      ->t('Do not write any table row information.'),
    '#default_value' => $config
      ->get('settings.no_data'),
  );
  $form['add_drop_table'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Add drop table'),
    '#description' => $this
      ->t('Write a DROP TABLE statement before each CREATE TABLE statement.'),
    '#default_value' => $config
      ->get('settings.add_drop_table'),
  );
  $form['single_transaction'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Single transaction'),
    '#description' => $this
      ->t('Sets the transaction isolation mode to REPEATABLE READ and sends a START TRANSACTION SQL statement to the server before dumping data.'),
    '#default_value' => $config
      ->get('settings.single_transaction'),
  );
  $form['lock_tables'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Lock tables'),
    '#description' => $this
      ->t('For each dumped database, lock all tables to be dumped before dumping them.'),
    '#default_value' => $config
      ->get('settings.lock_tables'),
  );
  $form['add_locks'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Add locks'),
    '#description' => $this
      ->t('Surround each table dump with LOCK TABLES and UNLOCK TABLES statements. This results in faster inserts when the dump file is reloaded.'),
    '#default_value' => $config
      ->get('settings.add_locks'),
  );
  $form['extended_insert'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Extended insert'),
    '#description' => $this
      ->t('Write INSERT statements using multiple-row syntax that includes several VALUES lists. This results in a smaller dump file and speeds up inserts when the file is reloaded.'),
    '#default_value' => $config
      ->get('settings.extended_insert'),
  );
  $form['complete_insert'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Complete insert'),
    '#description' => $this
      ->t('Use complete INSERT statements that include column names.'),
    '#default_value' => $config
      ->get('settings.complete_insert'),
  );
  $form['disable_keys'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable keys'),
    '#description' => $this
      ->t('Makes loading the dump file faster because the indexes are created after all rows are inserted.'),
    '#default_value' => $config
      ->get('settings.disable_keys'),
  );
  $form['no_create_info'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('No create info'),
    '#description' => $this
      ->t('Do not write CREATE TABLE statements that create each dumped table.'),
    '#default_value' => $config
      ->get('settings.no_create_info'),
  );
  $form['skip_triggers'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Skip triggers'),
    '#description' => $this
      ->t('Include triggers for each dumped table in the output.'),
    '#default_value' => $config
      ->get('settings.skip_triggers'),
  );
  $form['add_drop_trigger'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Add drop trigger'),
    '#description' => $this
      ->t('Write a DROP TRIGGER statement before each CREATE TRIGGER statement.'),
    '#default_value' => $config
      ->get('settings.add_drop_trigger'),
  );
  $form['routines'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Routines'),
    '#description' => $this
      ->t('Include stored routines (procedures and functions) for the dumped databases in the output. '),
    '#default_value' => $config
      ->get('settings.routines'),
  );
  $form['hex_blob'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Hex blob'),
    '#description' => $this
      ->t('Dump binary columns using hexadecimal notation.'),
    '#default_value' => $config
      ->get('settings.hex_blob'),
  );
  $form['databases'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Databases'),
    '#description' => $this
      ->t('Treat all name arguments as database names.'),
    '#default_value' => $config
      ->get('settings.databases'),
  );
  $form['add_drop_database'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Add drop database'),
    '#description' => $this
      ->t('Write a DROP DATABASE statement before each CREATE DATABASE statement.'),
    '#default_value' => $config
      ->get('settings.add_drop_database'),
  );
  $form['skip_tz_utc'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Skip TZ UTC'),
    '#description' => $this
      ->t('This option enables TIMESTAMP columns to be dumped and reloaded between servers in different time zones.'),
    '#default_value' => $config
      ->get('settings.skip_tz_utc'),
  );
  $form['no_autocommit'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('No autocommit'),
    '#description' => $this
      ->t('Please see http://dev.mysql.com/doc/refman/5.7/en/commit.html'),
    '#default_value' => $config
      ->get('settings.no_autocommit'),
  );
  $form['skip_comments'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Skip comments'),
    '#description' => $this
      ->t('Write additional information in the dump file such as program version, server version, and host.'),
    '#default_value' => $config
      ->get('settings.skip_comments'),
  );
  $form['skip_dump_date'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Skip dump date'),
    '#description' => $this
      ->t('Produces a date comment at the end of the dump file.'),
    '#default_value' => $config
      ->get('settings.skip_dump_date'),
  );
  $form['default_character_set'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Default character set'),
    '#description' => $this
      ->t('Please see http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html'),
    '#default_value' => $config
      ->get('settings.default_character_set'),
  );
  $form['where'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Where'),
    '#description' => $this
      ->t('Dump only rows selected by the given WHERE condition.'),
    '#default_value' => $config
      ->get('settings.where'),
  );
  return parent::buildForm($form, $form_state);
}