public function YamlFormTime::form in YAML Form 8
Gets the actual configuration form array to be built.
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 An associative array contain the element's configuration form without any default values..
Overrides YamlFormElementBase::form
File
- src/
Plugin/ YamlFormElement/ YamlFormTime.php, line 52
Class
- YamlFormTime
- Provides a 'yamlform_time' element.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
// Append supported time input format to #default_value description.
$form['general']['default_value']['#description'] .= '<br />' . $this
->t('Accepts any time in any <a href="https://www.gnu.org/software/tar/manual/html_chapter/tar_7.html#Date-input-formats">GNU Date Input Format</a>. Strings such as now, +2 hours, and 4:30 PM are all valid.');
// Time.
$form['time'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Time settings'),
];
$form['time']['time_format'] = [
'#type' => 'yamlform_select_other',
'#title' => $this
->t('Time format'),
'#description' => $this
->t("Time format is only applicable for browsers that do not have support for the HTML5 time element. Browsers that support the HTML5 time element will display the time using the user's preferred format. Time format is used to format the submitted value."),
'#options' => [
'g:i A' => $this
->t('12 hour (@time)', [
'@time' => date('g:i A'),
]),
'g:i:s A' => $this
->t('12 hour with seconds (@time)', [
'@time' => date('g:i:s A'),
]),
'H:i' => $this
->t('24 hour (@time)', [
'@time' => date('H:i'),
]),
'H:i:s' => $this
->t('24 hour with seconds (@time)', [
'@time' => date('H:i:s'),
]),
],
'#other__option_label' => $this
->t('Custom...'),
'#other__placeholder' => $this
->t('Custom time format...'),
'#other__description' => $this
->t('Enter time format using <a href="http://php.net/manual/en/function.date.php">Time Input Format</a>.'),
];
$form['time']['min'] = [
'#type' => 'yamlform_time',
'#title' => $this
->t('Min'),
'#description' => $this
->t('Specifies the minimum time.'),
];
$form['time']['max'] = [
'#type' => 'yamlform_time',
'#title' => $this
->t('Max'),
'#description' => $this
->t('Specifies the maximum time.'),
];
$form['time']['step'] = [
'#type' => 'yamlform_select_other',
'#title' => $this
->t('Step'),
'#description' => $this
->t('Specifies the minute intervals.'),
'#options' => [
'' => $this
->t('1 minute'),
30 => $this
->t('5 minutes'),
600 => $this
->t('10 minutes'),
900 => $this
->t('15 minutes'),
1200 => $this
->t('20 minutes'),
1800 => $this
->t('30 minutes'),
],
'#other__type' => 'number',
'#other__description' => $this
->t('Enter interval in seconds.'),
];
return $form;
}