You are here

public function DemoAdminSettings::buildForm in Demonstration site (Sandbox / Snapshot) 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/DemoAdminSettings.php, line 26

Class

DemoAdminSettings
This class will return the form demo_admin_settings.

Namespace

Drupal\demo\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  \Drupal::messenger()
    ->addMessage(t('Snapshot file system path: private://' . \Drupal::state()
    ->get('demo_dump_path', 'demo')), 'warning');
  $intervals = [
    // 0, 5, 10, 15, 30 minutes.
    0,
    300,
    600,
    900,
    1800,
    // 1-6, 9, 12 hours.
    3600,
    3600 * 2,
    3600 * 3,
    3600 * 4,
    3600 * 5,
    3600 * 6,
    3600 * 9,
    3600 * 12,
    // 1-3 days.
    86400,
    86400 * 2,
    86400 * 3,
    // 1, 2, 3 weeks.
    604800,
    604800 * 2,
    604800 * 3,
    // 1, 3 months.
    86400 * 30,
    86400 * 90,
  ];
  $options = build_options($intervals);
  $demo_manage_form_url = Url::fromRoute('demo.manage_form');
  $cron_url = Url::fromRoute('system.cron_settings');
  $form['demo_reset_interval'] = [
    '#type' => 'select',
    '#title' => t('Automatic reset interval'),
    '#required' => FALSE,
    '#default_value' => \Drupal::config('demo.settings')
      ->get('demo_reset_interval', 0),
    '#options' => $options,
    '#empty_value' => 0,
    '#description' => t('Requires a ' . Link::fromTextAndUrl(t('default snapshot'), $demo_manage_form_url) . ' and ' . Link::fromTextAndUrl(t('cron'), $cron_url) . ' to run in the configured interval.'),
  ];
  return parent::buildForm($form, $form_state);
}