public static function OfficeHoursList::processOfficeHoursSlot in Office Hours 8
Process an individual element.
Build the form element. When creating a form using Form API #process, note that $element['#value'] is already set.
Parameters
$element:
\Drupal\Core\Form\FormStateInterface $form_state:
$complete_form:
Return value
array The enriched element, identical to first parameter.
1 call to OfficeHoursList::processOfficeHoursSlot()
- OfficeHoursSlot::processOfficeHoursSlot in src/
Element/ OfficeHoursSlot.php - Process an individual element.
1 method overrides OfficeHoursList::processOfficeHoursSlot()
- OfficeHoursSlot::processOfficeHoursSlot in src/
Element/ OfficeHoursSlot.php - Process an individual element.
File
- src/
Element/ OfficeHoursList.php, line 113
Class
- OfficeHoursList
- Provides a one-line text field form element for the List Widget.
Namespace
Drupal\office_hours\ElementCode
public static function processOfficeHoursSlot(&$element, FormStateInterface $form_state, &$complete_form) {
$field_settings = $element['#field_settings'];
$day = isset($element['#value']['day']) ? $element['#value']['day'] : '';
$day_delta = $element['#daydelta'];
$element['#attributes']['class'][] = 'form-item';
$element['#attributes']['class'][] = 'office-hours-slot';
$element['day'] = [
'#type' => 'select',
'#options' => OfficeHoursDateHelper::weekDays(FALSE),
'#default_value' => $day,
];
$element['starthours'] = [
'#type' => $field_settings['element_type'],
// datelist, datetime.
'#field_settings' => $field_settings,
// Get the valid, restricted hours. Date API doesn't provide a straight method for this.
'#hour_options' => OfficeHoursDateHelper::hours($field_settings['time_format'], FALSE, $field_settings['limit_start'], $field_settings['limit_end']),
// Attributes for element \Drupal\Core\Datetime\Element\Datelist - Start.
'#date_part_order' => in_array($field_settings['time_format'], [
'g',
'h',
]) ? [
'hour',
'minute',
'ampm',
] : [
'hour',
'minute',
],
'#date_increment' => $field_settings['increment'],
'#date_time_element' => 'time',
'#date_time_format' => OfficeHoursDateHelper::getTimeFormat($field_settings['time_format']),
'#date_timezone' => '+0000',
];
$element['endhours'] = $element['starthours'];
$element['starthours']['#default_value'] = isset($element['#value']['starthours']) ? $element['#value']['starthours'] : NULL;
$element['endhours']['#default_value'] = isset($element['#value']['endhours']) ? $element['#value']['endhours'] : NULL;
$element['comment'] = !$field_settings['comment'] ? NULL : [
'#type' => 'textfield',
'#default_value' => isset($element['#value']['comment']) ? $element['#value']['comment'] : NULL,
'#size' => 20,
'#maxlength' => 255,
'#field_settings' => $field_settings,
];
// Copied from EntityListBuilder::buildOperations().
$element['operations'] = [
'data' => OfficeHoursList::getDefaultOperations($element),
];
$element['day_delta'] = [
'#type' => 'value',
'#value' => $day_delta,
];
return $element;
}