work_time-1.0.x-dev/src/Form/WorkTimeSettingsForm.php
src/Form/WorkTimeSettingsForm.php
<?php
namespace Drupal\work_time\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Configuration form for a work time entity type.
*/
class WorkTimeSettingsForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'work_time_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$month = date('Y-m');
$week = date('Y-\WW');
$config = \Drupal::config('worktime.settings');
$defaultFilter = $config->get('filter');
$form['#attributes']['class'][] = 'row';
$form['type'] = [
'#type' => 'select',
'#title' => $this->t('Type'),
'#default_value' => 'week',
'#options' => [
'week' => $this->t('Week'),
'month' => $this->t('Month'),
],
'#attributes' => [
'class' => ['type-timeline', 'w-auto'],
],
'#wrapper_attributes' => [
'class' => ['container-inline', 'col-auto'],
],
];
$form['date'] = [
'#type' => 'date',
'#title' => $this->t('Filter'),
'#default_value' => $$defaultFilter,
'#attributes' => [
'class' => ['date-timeline', 'w-auto'],
'type' => $defaultFilter,
],
'#wrapper_attributes' => [
'class' => ['container-inline', 'col-auto'],
],
];
$form['timeline'] = [
'#type' => 'container',
'#title' => $this->t('Attendance'),
'#attributes' => [
'class' => ['timeline'],
'id' => 'fingerprint-timeline',
'data-url' => Url::fromRoute('work_time.ajax_timeline')->toString(),
],
'list' => [],
];
$form['#attached'] = [
'library' => [
'work_time/work-time-line',
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->messenger()->addStatus($this->t('The configuration has been updated.'));
}
}
