You are here

fullcalendar_view.module in Fullcalendar View 8.2

Full Canlendar Views module help and theme functions.

File

fullcalendar_view.module
View source
<?php

/**
 * @file
 * Full Canlendar Views module help and theme functions.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Datetime\DrupalDateTime;

// Store the preprocess theme functions in a separate .inc file.
\Drupal::moduleHandler()
  ->loadInclude('fullcalendar_view', 'inc', 'fullcalendar_view.theme');

/**
 * Implements hook_theme().
 */
function fullcalendar_view_theme($existing, $type, $theme, $path) {
  return [
    'fullcalendar' => [
      'file' => 'fullcalendar_view.theme.inc',
    ],
  ];
}

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 *
 * Prepopulate the datetime field with the date passed from query parameter.
 */
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]) && isset($form[$start_field]['widget'][0])) {

      // 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);
      }
    }
  }
}