function social_event_date_all_day_checkbox in Open Social 8.4
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
- 8.3 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
- 8.5 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
- 8.6 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
- 8.7 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
- 8.8 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
- 10.3.x modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
- 10.0.x modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
- 10.1.x modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
- 10.2.x modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
Add 'All day' checkbox to event datetime field.
1 string reference to 'social_event_date_all_day_checkbox'
- social_event_field_widget_form_alter in modules/
social_features/ social_event/ social_event.module - Implements hook_field_widget_form_alter().
File
- modules/
social_features/ social_event/ social_event.module, line 462 - The Social event module.
Code
function social_event_date_all_day_checkbox(&$element, FormStateInterface $form_state, $date) {
// Time field should disappear when 'All day' is checked.
$state = [
':input[name="event_all_day"]' => [
'checked' => TRUE,
],
];
$element['time']['#states'] = [
'invisible' => $state,
];
$form_input = $form_state
->getUserInput();
$date = $element['#value']['object'];
if (!empty($form_input['op']) && isset($form_input['event_all_day'])) {
$element['time']['#value'] = '00:01:00';
$element['event_all_day']['#value'] = (bool) $form_input['event_all_day'];
}
elseif ($date instanceof DrupalDateTime && social_event_date_is_all_day($date)) {
$element['time']['#value'] = '00:01:00';
$element['event_all_day']['#value'] = TRUE;
}
}