You are here

function views_timelinejs_plugin_style_timelinejs::options_form in Views TimelineJS integration 7

Same name and namespace in other branches
  1. 7.3 views_timelinejs_plugin_style_timelinejs.inc \views_timelinejs_plugin_style_timelinejs::options_form()

Define options form.

Overrides views_plugin_style::options_form

File

./views_timelinejs_plugin_style_timelinejs.inc, line 96
Views Style.

Class

views_timelinejs_plugin_style_timelinejs
Unformatted style plugin.

Code

function options_form(&$form, &$form_state) {
  $handlers = $this->display->handler
    ->get_handlers('field');
  if (empty($handlers)) {
    $form['error_markup'] = array(
      '#prefix' => '<div class="error messages">',
      '#markup' => t('You need at least one field before you can configure TimelineJS.'),
      '#suffix' => '</div>',
    );
    return;
  }
  $media_fields = array(
    '0' => t('None'),
  );
  $date_fields = array(
    '0' => t('None'),
  );
  $text_fields = array(
    '0' => t('None'),
  );
  $tag_fields = array(
    '0' => t('None'),
  );

  // Load all date_source plugins.
  ctools_include('plugins');
  $date_sources = ctools_get_plugins('views_timelinejs', 'date_sources');
  $media_sources = ctools_get_plugins('views_timelinejs', 'media_sources');
  $tag_sources = ctools_get_plugins('views_timelinejs', 'tag_sources');

  // Go through all the field handlers to check support.
  foreach ($handlers as $field => $handler) {

    // Get a nice name for the field.
    $field_names[$field] = $handler
      ->ui_name();
    if ($label = $handler
      ->label()) {
      $field_names[$field] .= ' ("' . $label . '")';
    }
    if (isset($handler->definition['field_name'])) {
      $field_name = $handler->definition['field_name'];
      $field_info = field_info_field($field_name);
    }

    // Use any views field as a text source.
    $text_fields[$field] = $field_names[$field];

    // Check if field is supported as a date source.
    foreach ($date_sources as $source) {
      if (get_class($handler) == $source['handler_name']) {
        if ($field_info['type'] == $source['field_type'] || $field == 'created' || $field == 'changed') {
          $date_fields[$field] = $field_names[$field];
        }
      }
    }

    // Check if field is a supported media source.
    foreach ($media_sources as $source) {
      if (get_class($handler) == $source['handler_name']) {
        if (isset($field_info['type']) && $field_info['type'] == $source['field_type']) {
          $media_fields[$field] = $field_names[$field];
        }
      }
    }

    // Check if field is a supported tag source.
    foreach ($tag_sources as $source) {
      if (get_class($handler) == $source['handler_name']) {
        if (isset($field_info['type']) && $field_info['type'] == $source['field_type']) {
          $tag_fields[$field] = $field_names[$field];
        }
      }
    }
  }

  // Timeline general configuration.
  $form['timeline_config'] = array(
    '#type' => 'fieldset',
    '#title' => t('General configuration'),
    '#description' => t('Settings for how the Timeline will behave.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['timeline_config']['hash_bookmark'] = array(
    '#type' => 'select',
    '#title' => 'Hash Bookmarks',
    '#description' => t('On each slide, a # will be added to the end of the url in the url bar. These urls are bookmarkable, so you can share or return to the same place in the timeline later.'),
    '#options' => array(
      '0' => t('No'),
      '1' => t('Yes'),
    ),
    '#default_value' => $this->options['timeline_config']['hash_bookmark'],
  );
  $form['timeline_config']['start_at_end'] = array(
    '#type' => 'select',
    '#title' => 'Start at the end',
    '#description' => t('The most recent event will be shown first.'),
    '#options' => array(
      '0' => t('No'),
      '1' => t('Yes'),
    ),
    '#default_value' => $this->options['timeline_config']['start_at_end'],
  );
  $form['timeline_config']['start_at_current'] = array(
    '#type' => 'select',
    '#title' => 'Start at Current',
    '#description' => t('The slide closest to current time.'),
    '#options' => array(
      '0' => t('No'),
      '1' => t('Yes'),
    ),
    '#default_value' => $this->options['timeline_config']['start_at_current'],
  );
  $form['timeline_config']['start_zoom_adjust'] = array(
    '#type' => 'select',
    '#title' => 'Zoom Level',
    '#description' => t('Set the default zoom level.'),
    '#options' => array(
      '-9' => t('-9'),
      '-8' => t('-8'),
      '-7' => t('-7'),
      '-6' => t('-6'),
      '-5' => t('-5'),
      '-4' => t('-4'),
      '-3' => t('-3'),
      '-2' => t('-2'),
      '-1' => t('-1'),
      '0' => t('0'),
      '1' => t('1'),
      '2' => t('2'),
      '3' => t('3'),
      '4' => t('4'),
      '5' => t('5'),
      '6' => t('6'),
      '7' => t('7'),
      '8' => t('8'),
      '9' => t('9'),
    ),
    '#default_value' => $this->options['timeline_config']['start_zoom_adjust'],
  );
  $form['timeline_config']['maptype'] = array(
    '#type' => 'select',
    '#title' => 'Map Type',
    '#description' => t('Select the type of map.'),
    '#options' => array(
      '0' => t('None'),
      'Stamen Maps' => array(
        'toner' => t('Toner'),
        'toner-lines' => t('Toner Lines'),
        'toner-labels' => t('Toner Labels'),
        'watercolor' => t('Watercolor'),
        'sterrain' => t('Terrain'),
      ),
      'Google Maps' => array(
        'ROADMAP' => t('Roadmap'),
        'TERRAIN' => t('Terrain'),
        'HYBRID' => t('Hybrid'),
        'SATELLITE' => t('Satellite'),
      ),
    ),
    '#default_value' => $this->options['timeline_config']['maptype'],
  );
  $form['timeline_config']['gmap_key'] = array(
    '#type' => 'textfield',
    '#title' => 'GMAP API Key',
    '#description' => t('Due to recent changes to the Google Maps API, you need a <a href="https://developers.google.com/maps/documentation/javascript/tutorial#api_key">API Key</a> in order to use custom map types.'),
    '#default_value' => $this->options['timeline_config']['gmap_key'],
    '#states' => array(
      'invisible' => array(
        'select[name="style_options[timeline_config][maptype]"]' => array(
          'value' => '0',
        ),
      ),
    ),
  );
  $form['timeline_config']['language'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#title' => 'Language',
    '#description' => t('The language <a href="https://github.com/NUKnightLab/TimelineJS#language">code</a>. Leave blank for the site language.'),
    '#default_value' => $this->options['timeline_config']['language'],
  );
  $form['timeline_config']['font'] = array(
    '#type' => 'select',
    '#title' => 'Font',
    '#description' => t('This setting will only have an effect if the selected font is available to the site (ie @font-face).'),
    '#options' => array(
      'default' => t('Default'),
      'AbrilFatface-Average' => 'AbrilFatface-Average',
      'Arvo-PTSans' => 'Arvo-PTSans',
      'Bevan-PotanoSans' => 'Bevan-PotanoSans',
      'BreeSerif-OpenSans' => 'BreeSerif-OpenSans',
      'DroidSerif-DroidSans' => 'DroidSerif-DroidSans',
      'Georgia-Helvetica' => 'Georgia-Helvetica',
      'Lekton-Molengo' => 'Lekton-Molengo',
      'Merriweather-NewsCycle' => 'Merriweather-NewsCycle',
      'NewsCycle-Merriweather' => 'NewsCycle-Merriweather',
      'NixieOne-Ledger' => 'NixieOne-Ledger',
      'Pacifico-Arimo' => 'Pacifico-Arimo',
      'PlayfairDisplay-Muli' => 'PlayfairDisplay-Muli',
      'PoiretOne-Molengo' => 'PoiretOne-Molengo',
      'PTSerif-PTSans' => 'PTSerif-PTSans',
      'PT' => 'PT',
      'Rancho-Gudea' => 'Rancho-Gudea',
      'SansitaOne-Kameron' => 'SansitaOne-Kameron',
    ),
    '#default_value' => $this->options['timeline_config']['font'],
  );
  $form['timeline_config']['debug'] = array(
    '#type' => 'select',
    '#title' => 'Debug to Console',
    '#description' => t('Log events to the javascript console.'),
    '#options' => array(
      '0' => t('No'),
      '1' => t('Yes'),
    ),
    '#default_value' => $this->options['timeline_config']['debug'],
  );

  // Field mapping.
  $form['timeline_fields'] = array(
    '#type' => 'fieldset',
    '#title' => t('Field mappings'),
    '#description' => t('Fields used to construct the timeline events.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['timeline_fields']['headline'] = array(
    '#type' => 'select',
    '#options' => $text_fields,
    '#title' => t('Headline'),
    '#required' => TRUE,
    '#description' => t('Plain text; a high level summary.'),
    '#default_value' => $this->options['timeline_fields']['headline'],
  );
  $form['timeline_fields']['bodytext'] = array(
    '#type' => 'select',
    '#options' => $text_fields,
    '#title' => t('Body text'),
    '#description' => t('Plain text; a paragraph or two of optional details.'),
    '#default_value' => $this->options['timeline_fields']['bodytext'],
  );
  $form['timeline_fields']['date'] = array(
    '#type' => 'select',
    '#options' => $date_fields,
    '#title' => t('Start and End date'),
    '#required' => TRUE,
    '#description' => t('Required start and optional end of an event; can be a date field or timestamp.'),
    '#default_value' => $this->options['timeline_fields']['date'],
  );
  $form['timeline_fields']['media'] = array(
    '#type' => 'select',
    '#options' => $media_fields,
    '#title' => t('Media URL'),
    '#description' => t('Drupal core image fields and link fields are supported; must contain a raw URL to an image or video.'),
    '#default_value' => $this->options['timeline_fields']['media'],
  );
  $form['timeline_fields']['credit'] = array(
    '#type' => 'select',
    '#title' => t('Media Credit'),
    '#description' => t('Byline naming the author or attributing the source.'),
    '#options' => $text_fields,
    '#default_value' => $this->options['timeline_fields']['credit'],
  );
  $form['timeline_fields']['caption'] = array(
    '#type' => 'select',
    '#title' => t('Media Caption'),
    '#description' => t('Brief explanation of the media content.'),
    '#options' => $text_fields,
    '#default_value' => $this->options['timeline_fields']['caption'],
  );
  $form['timeline_fields']['tag'] = array(
    '#type' => 'select',
    '#options' => $tag_fields,
    '#title' => t('Tag'),
    '#description' => t('Content tagging; maximum of 6 tags.'),
    '#default_value' => $this->options['timeline_fields']['tag'],
  );

  // Timeline display configuration.
  $units = array(
    0 => 'px',
    1 => '%',
  );
  $form['timeline_theme'] = array(
    '#type' => 'fieldset',
    '#title' => t('Display configuration'),
    '#description' => t('Settings for how the Timeline will look.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['timeline_theme']['width'] = array(
    '#type' => 'textfield',
    '#title' => 'Width of the timeline',
    '#description' => t('The width of the timeline.'),
    '#default_value' => $this->options['timeline_theme']['width'],
  );
  $form['timeline_theme']['width_unit'] = array(
    '#type' => 'radios',
    '#title' => t('Units for the width'),
    '#description' => t('Choose which units will be used to define the width of the timeline.'),
    '#default_value' => $this->options['timeline_theme']['width_unit'],
    '#options' => $units,
  );
  $form['timeline_theme']['height'] = array(
    '#type' => 'textfield',
    '#title' => 'Height of the timeline',
    '#description' => t('The height of the timeline.'),
    '#default_value' => $this->options['timeline_theme']['height'],
  );
  $form['timeline_theme']['height_unit'] = array(
    '#type' => 'radios',
    '#title' => t('Units for the height'),
    '#description' => t('Choose which units will be used to define the height of the timeline.'),
    '#default_value' => $this->options['timeline_theme']['height_unit'],
    '#options' => $units,
  );
}