You are here

function social_event_date_all_day_checkbox in Open Social 8.5

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
  2. 8.3 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
  3. 8.4 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
  4. 8.6 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
  5. 8.7 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
  6. 8.8 modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
  7. 10.3.x modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
  8. 10.0.x modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
  9. 10.1.x modules/social_features/social_event/social_event.module \social_event_date_all_day_checkbox()
  10. 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 544
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;
  }
}