You are here

function fullcalendar_fullcalendar_options_process in FullCalendar 7.2

Implements hook_fullcalendar_options_process().

File

includes/fullcalendar.fullcalendar.inc, line 479
Provides default FullCalendar configuration options.

Code

function fullcalendar_fullcalendar_options_process(&$variables, &$settings) {
  $view =& $variables['view'];
  static $fc_dom_id = 1;
  if (empty($view->dom_id)) {
    $view->dom_id = 'fc-' . $fc_dom_id++;
  }
  $options = $view->style_plugin->options;
  $options['gcal'] = array();
  foreach ($view->field as $field) {
    if ($field->field == 'gcal') {
      $options['gcal'][] = $field
        ->render(array());
    }
  }
  unset($options['fields']);
  $settings += $options + array(
    'view_name' => $view->name,
    'view_display' => $view->current_display,
  );

  // Add JS and CSS files.
  $variables['element']['#attached'] = array(
    'library' => array(
      array(
        'fullcalendar',
        'fullcalendar',
      ),
    ),
    'js' => array(
      ctools_attach_js('fullcalendar.library', 'fullcalendar') => array(
        'group' => JS_LIBRARY,
      ),
      ctools_attach_js('fullcalendar.views', 'fullcalendar') => array(
        'weight' => 20,
      ),
    ),
    'css' => array(
      ctools_attach_css('fullcalendar.theme', 'fullcalendar'),
    ),
  );
  if (!empty($settings['ajax'])) {
    $variables['element']['#attached']['js'][] = ctools_attach_js('fullcalendar.ajax', 'fullcalendar');
  }

  // Add CSS and JS for each option plugin that provides it.
  fullcalendar_include_api();
  $weights = array();
  $delta = 0;
  foreach (module_invoke_all('fullcalendar_options_info') as $module => $info) {

    // If a weight is specified, use it.
    if (isset($info['weight']) && !isset($weights[$info['weight']])) {
      $weights[$info['weight']] = $module;
    }
    else {
      while (isset($weights[$delta])) {
        $delta++;
      }
      $weights[$delta] = $module;
    }

    // If this function is being provided by another module, set the parent.
    $parent = isset($info['parent']) ? $info['parent'] : $module;
    if (!empty($info['js'])) {
      $variables['element']['#attached']['js'][] = ctools_attach_js("{$module}.fullcalendar", $parent);
    }
    if (!empty($info['css'])) {
      $variables['element']['#attached']['css'][] = ctools_attach_css("{$module}.fullcalendar", $parent);
    }
  }
  ksort($weights);
  $settings['weights'] = array_values($weights);
}