function fullcalendar_view_form_node_form_alter in Fullcalendar View 5.x
Same name and namespace in other branches
- 8.3 fullcalendar_view.module \fullcalendar_view_form_node_form_alter()
- 8 fullcalendar_view.module \fullcalendar_view_form_node_form_alter()
- 8.2 fullcalendar_view.module \fullcalendar_view_form_node_form_alter()
- 6.x fullcalendar_view.module \fullcalendar_view_form_node_form_alter()
Implements hook_form_BASE_FORM_ID_alter().
Prepopulate the datetime field with the date passed from query parameter.
File
- ./
fullcalendar_view.module, line 30 - Full Canlendar Views module help and theme functions.
Code
function fullcalendar_view_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Event start date from query parameter.
$start = \Drupal::request()->query
->get('start');
// Field name of the start date from query parameter.
$start_field = \Drupal::request()->query
->get('start_field');
if (!empty($start) && !empty($start_field)) {
$node = $form_state
->getFormObject()
->getEntity();
// Only handle new node with the start field.
if ($node
->isNew() && isset($form[$start_field]['widget'][0]['value'])) {
// Only handle datetime field.
if ($form[$start_field]['widget'][0]['value']['#type'] === 'datetime') {
// Prepopulate the start date field as the event date.
$form[$start_field]['widget'][0]['value']['#default_value'] = new DrupalDateTime($start, 'UTC');
}
}
}
}