You are here

public function OptimizedbAdminForm::buildForm in OptimizeDB 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/OptimizedbAdminForm.php, line 24

Class

OptimizedbAdminForm
Settings optimizedb module.

Namespace

Drupal\optimizedb\Form

Code

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

  // Messages status execute operation.
  optimizedb_operation_messages($form);
  $form['executing_commands'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Executing commands manually'),
  ];
  $form['executing_commands']['optimize'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Optimize tables'),
    '#submit' => [
      [
        $this,
        'optimizeTablesSubmit',
      ],
    ],
  ];
  $form['optimize_table'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Optimization settings database'),
  ];
  $last_optimization = $config
    ->get('last_optimization');
  $form['optimize_table']['optimization_period'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Receive notification of the need to optimize the database, every.'),
    '#description' => $this
      ->t('Last run: @date ago.', [
      '@date' => _optimizedb_date($last_optimization),
    ]),
    '#default_value' => $config
      ->get('optimization_period'),
    '#options' => [
      0 => $this
        ->t('Disabled'),
      1 => $this
        ->t('@count day', [
        '@count' => 1,
      ]),
      2 => $this
        ->t('@count day', [
        '@count' => 2,
      ]),
      7 => $this
        ->t('@count days', [
        '@count' => 7,
      ]),
      14 => $this
        ->t('@count days', [
        '@count' => 14,
      ]),
      30 => $this
        ->t('@count days', [
        '@count' => 30,
      ]),
      60 => $this
        ->t('@count days', [
        '@count' => 60,
      ]),
    ],
  ];
  $size_tables = format_size($config
    ->get('tables_size'));
  $form['optimize_table']['tables'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Current information on all database tables.'),
    '#markup' => $this
      ->t('The size of all tables in the database: <b>@size</b>. View the size of the tables separately, you can on the page - <a href="@url">List of tables in the database</a>.', [
      '@size' => $size_tables,
      '@url' => Url::fromRoute('optimizedb.list_tables')
        ->toString(),
    ]),
  ];
  return parent::buildForm($form, $form_state);
}