work_time-1.0.x-dev/modules/fingerprint/src/Form/FingerprintConfigForm.php
modules/fingerprint/src/Form/FingerprintConfigForm.php
<?php
namespace Drupal\fingerprint\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Configuration form for a work time fingerprint entity type.
*/
class FingerprintConfigForm extends ConfigFormBase {
/**
* Name of the config.
*
* @var string
*/
public static $configName = 'fingerprint.settings';
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [self::$configName];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'fingerprint_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config(self::$configName);
$form['shift'] = [
'#title' => $this->t('Shift schedule'),
'#description' => $this->t('Enter schedule hour in/out time, Example "08:00-17:30,5:00-14:30,14:00-22:30,... Format H:i"'),
'#type' => 'textarea',
'#default_value' => $config->get('shift'),
];
$form['shift_night'] = [
'#title' => $this->t('Night shift begin'),
'#description' => $this->t('Hours begin night shift, Example: 19:00'),
'#type' => 'textfield',
'#default_value' => $config->get('shift_night'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Retrieve the configuration.
$this->config(self::$configName)
// Set the submitted configuration setting.
->set('shift', $form_state->getValue('shift'))
->set('shift_night', $form_state->getValue('shift_night'))
->save();
$this->messenger()
->addStatus($this->t('The configuration has been updated.'));
}
}
