View source
<?php
namespace Drupal\webform_scheduled_tasks\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class WebformSanitizeConfigForm extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->configFactory()
->get('webform_scheduled_tasks.config');
$form['description'] = [
'#markup' => $this
->t('Use this form to configure Webform Scheduled Tasks.'),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
$form['settings'] = [
'#type' => 'details',
'#tree' => TRUE,
'#open' => TRUE,
'#title' => $this
->t('Webform Scheduled Tasks Settings'),
];
$form['settings']['description'] = [
'#markup' => $this
->t('This is a scheduled job that runs every "x" minutes and is designed to sanitize a specified Webform field.'),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
$form['settings']['field_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Field Name'),
'#description' => $this
->t('Provide the Field be sanitized.'),
'#default_value' => $config
->get("field_name"),
'#required' => TRUE,
];
$form['settings']['sanitized_value'] = [
'#type' => 'textfield',
'#title' => $this
->t('Sanitized Value'),
'#description' => $this
->t('Provide the value to overwrite the Field with.'),
'#default_value' => $config
->get("sanitized_value"),
'#required' => TRUE,
];
$form['settings']['run_interval'] = [
'#type' => 'textfield',
'#title' => $this
->t('Run Interval'),
'#description' => $this
->t('Set the interval in minutes between runs. Default 1440 (24 hours).'),
'#default_value' => $config
->get("run_interval"),
'#required' => TRUE,
];
$form['settings']['last_run'] = [
'#markup' => $this
->t('Last Run: @last_run', [
'@last_run' => $config
->get("last_run"),
]),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
$form['settings']['manual'] = [
'#type' => 'submit',
'#value' => $this
->t('Save and Run Webform Sanitization'),
'#submit' => [
[
$this,
'submitForm',
],
'webform_scheduled_tasks_do_actions',
],
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$field_name = $values['settings']['field_name'];
$sanitized_value = $values['settings']['sanitized_value'];
$run_interval = $values['settings']['run_interval'];
webform_scheduled_tasks_set_config('field_name', $field_name);
webform_scheduled_tasks_set_config('sanitized_value', $sanitized_value);
webform_scheduled_tasks_set_config('run_interval', $run_interval);
parent::submitForm($form, $form_state);
}
protected function getEditableConfigNames() {
return [
'webform_scheduled_tasks.config',
];
}
public function getFormId() {
return 'webform_scheduled_tasks_settings';
}
}