You are here

function fullcalendar_plugin_style_fullcalendar::init in FullCalendar 7.2

Map old setting names to new ones. @todo Remove in 7.x-2.1.

Overrides views_plugin_style::init

File

includes/views/plugins/fullcalendar_plugin_style_fullcalendar.inc, line 21
Contains the FullCalendar style plugin.

Class

fullcalendar_plugin_style_fullcalendar
@file Contains the FullCalendar style plugin.

Code

function init(&$view, &$display, $options = NULL) {
  parent::init($view, $display, $options);
  if (!empty($options)) {

    // Set up a rename map from the old names to new names.
    $rename_map = array(
      'times' => array(
        'fc_default_date' => 'default_date',
        'fc_date' => 'date',
        'fc_timeformat' => 'timeformat',
      ),
      'header' => array(
        'fc_left' => 'left',
        'fc_center' => 'center',
        'fc_right' => 'right',
      ),
      'modules' => array(
        'fc_theme' => 'theme',
        'fc_window' => 'sameWindow',
        'fc_url_colorbox' => 'colorbox',
        'fc_url_colorbox_class' => 'colorboxClass',
        'fc_url_colorbox_height' => 'colorboxHeight',
        'fc_url_colorbox_width' => 'colorboxWidth',
      ),
      'display' => array(
        'fc_view' => 'defaultView',
        'fc_firstday' => 'firstDay',
        'fc_weekmode' => 'weekMode',
        'fc_content_height' => 'contentHeight',
      ),
    );
    $new_options = array();
    foreach ($options as $grouping => $option) {
      if (!isset($rename_map[$grouping])) {
        continue;
      }
      foreach ($rename_map[$grouping] as $old_option => $new_option) {
        if (!isset($options[$grouping][$old_option])) {
          continue;
        }

        // All new settings aren't nested, except date and default_date.
        if ($grouping == 'times' && in_array($old_option, array(
          'fc_default_date',
          'fc_date',
        ))) {
          $new_options[$grouping][$new_option] = $options[$grouping][$old_option];
        }
        else {
          $new_options[$new_option] = $options[$grouping][$old_option];
        }
      }
    }

    // Set out new variable for later usage.
    $this->time = empty($options['times']['fc_clock']) ? '12' : '24';

    // Add new options to defaults.
    $this
      ->unpack_options($this->options, array_filter($new_options));

    // Unset the obsolete settings.
    unset($this->options['display']);
    unset($this->options['modules']);
    unset($this->options['header']);
    unset($this->options['times']['fc_clock']);
    unset($this->options['times']['fc_date']);
    unset($this->options['times']['fc_default_date']);
    unset($this->options['times']['fc_timeformat']);
  }

  // Move Colorbox settings into their own array.
  $options = $this->options;
  if (isset($options['colorbox']) && !is_array($options['colorbox'])) {
    $colorbox = array();
    foreach ($options as $key => $value) {
      if (substr($key, 0, 8) == 'colorbox') {
        $colorbox[$key] = $value;
        unset($options[$key]);
      }
    }
    $options['colorbox'] = $colorbox;
    $this
      ->unpack_options($this->options, $options);
  }
}