You are here

function openlayers_views_style_data::options_form in Openlayers 6.2

Same name and namespace in other branches
  1. 7.2 modules/openlayers_views/views/openlayers_views_style_data.inc \openlayers_views_style_data::options_form()

Options form

File

modules/openlayers_views/views/openlayers_views_style_data.inc, line 30
This file holds style plugin for OpenLayers Views

Class

openlayers_views_style_data
@class Extension of the Views Plugin Syle for OpenLayers

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);
  $fields = array();

  // Get list of fields in this view & flag available geodata fields
  $handlers = $this->display->handler
    ->get_handlers('field');

  // Check for any fields, as the view needs them
  if (empty($handlers)) {
    $form['error_markup'] = array(
      '#value' => t('You need to enable at least one field before you can configure your field settings'),
      '#prefix' => '<div class="error form-item description">',
      '#suffix' => '</div>',
    );
    return;
  }

  // Go through fields
  foreach ($handlers as $field_id => $handler) {
    if ($handler->content_field['type'] == 'openlayers_wkt' && $handler->options['format'] !== 'openlayers_wkt') {
      form_set_error('', t('WKT Field %field not available
            because it is formatted as a map. Set its format to WKT Value to
            make it available.', array(
        '%field' => $handler->definition['title'],
      )));
    }
    else {
      $fields[$field_id] = $handler->definition['title'];
    }
  }

  // Data Source options
  $form['data_source'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#title' => t('Data Source'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['data_source']['value'] = array(
    '#type' => 'select',
    '#title' => t('Map Data Sources'),
    '#description' => t('Choose which sources of data that the map will provide features for.'),
    '#options' => array(
      'other_latlon' => t('Other: Lat/Lon Point'),
      'other_boundingbox' => t('Other: Bounding Box'),
      'openlayers_wkt' => t('OpenLayers WKT'),
    ),
    '#default_value' => $this->options['data_source']['value'],
  );

  // Other Lat and Lon data sources
  if (count($fields > 0)) {
    $form['data_source']['other_lat'] = array(
      '#type' => 'select',
      '#title' => t('Latitude Field'),
      '#description' => t('Choose a field for Latitude.  This should be a field that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_lat'],
      '#process' => array(
        'views_process_dependency',
      ),
      '#dependency' => array(
        'edit-style-options-data-source-value' => array(
          'other_latlon',
        ),
      ),
    );
    $form['data_source']['other_lon'] = array(
      '#type' => 'select',
      '#title' => t('Longitude Field'),
      '#description' => t('Choose a field for Longitude.  This should be a field that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_lon'],
      '#process' => array(
        'views_process_dependency',
      ),
      '#dependency' => array(
        'edit-style-options-data-source-value' => array(
          'other_latlon',
        ),
      ),
    );

    // Other: WKT
    $form['data_source']['openlayers_wkt'] = array(
      '#type' => 'select',
      '#title' => t('WKT Field'),
      '#description' => t('Choose the OpenLayers WKT field.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['openlayers_wkt'],
      '#process' => array(
        'views_process_dependency',
      ),
      '#dependency' => array(
        'edit-style-options-data-source-value' => array(
          'openlayers_wkt',
        ),
      ),
    );

    // Other: Bounding Box
    $form['data_source']['other_top'] = array(
      '#type' => 'select',
      '#title' => t('Top Field'),
      '#description' => t('Choose a field for Top.  This should be a field that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_top'],
      '#process' => array(
        'views_process_dependency',
      ),
      '#dependency' => array(
        'edit-style-options-data-source-value' => array(
          'other_boundingbox',
        ),
      ),
    );
    $form['data_source']['other_right'] = array(
      '#type' => 'select',
      '#title' => t('Right Field'),
      '#description' => t('Choose a field for Right.  This should be a field that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_right'],
      '#process' => array(
        'views_process_dependency',
      ),
      '#dependency' => array(
        'edit-style-options-data-source-value' => array(
          'other_boundingbox',
        ),
      ),
    );
    $form['data_source']['other_bottom'] = array(
      '#type' => 'select',
      '#title' => t('Bottom Field'),
      '#description' => t('Choose a field for Bottom.  This should be a field that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_bottom'],
      '#process' => array(
        'views_process_dependency',
      ),
      '#dependency' => array(
        'edit-style-options-data-source-value' => array(
          'other_boundingbox',
        ),
      ),
    );
    $form['data_source']['other_left'] = array(
      '#type' => 'select',
      '#title' => t('Left Field'),
      '#description' => t('Choose a field for Left.  This should be a field that is a decimal or float value.'),
      '#options' => $fields,
      '#default_value' => $this->options['data_source']['other_left'],
      '#process' => array(
        'views_process_dependency',
      ),
      '#dependency' => array(
        'edit-style-options-data-source-value' => array(
          'other_boundingbox',
        ),
      ),
    );
  }
  $form['data_source']['name_field'] = array(
    '#type' => 'select',
    '#title' => t('Title Field'),
    '#description' => t('Choose the field which will appear as a title on tooltips.'),
    '#options' => array_merge(array(
      '' => '',
    ), $fields),
    '#default_value' => $this->options['data_source']['name_field'],
  );
  $form['data_source']['keep_orig_name_field'] = array(
    '#type' => 'checkbox',
    '#title' => t('Keep non-rendered title field attribute'),
    '#description' => t('Check to ensure the title field will still be present as an attribute in its non-rendered form'),
    '#default_value' => $this->options['data_source']['keep_orig_name_field'],
  );
  $form['data_source']['description_field'] = array(
    '#type' => 'select',
    '#title' => t('Description Field'),
    '#description' => t('Choose the field which will appear as a description on tooltips.'),
    '#required' => FALSE,
    '#options' => array_merge(array(
      '' => '',
    ), $fields),
    '#default_value' => $this->options['data_source']['description_field'],
  );
  $form['data_source']['keep_orig_desc_field'] = array(
    '#type' => 'checkbox',
    '#title' => t('Keep non-rendered description field attribute'),
    '#description' => t('Check to ensure the description field will still be present as an attribute in its non-rendered form'),
    '#default_value' => $this->options['data_source']['keep_orig_desc_field'],
  );

  // Attributes and variable styling description
  $form['attributes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Attributes and Styling'),
    '#description' => t('Attributes are field data attached to each feature.  This can be used with styling to create Variable styling.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Make array of attributes
  $variable_fields = array();

  // Add name and description
  if (!empty($this->options['data_source']['name_field'])) {
    $variable_fields['name'] = '${name}';
  }
  if (!empty($this->options['data_source']['description_field'])) {
    $variable_fields['description'] = '${description}';
  }

  // Go through fields
  foreach ($this->view->display_handler
    ->get_handlers('field') as $field => $handler) {
    if ($field != $this->options['data_source']['name_field'] && $field != $this->options['data_source']['description_field']) {
      $variable_fields[$field] = '${' . $field . '}';
      $variable_fields[$field . '_rendered'] = '${' . $field . '_rendered}';
    }
  }
  $form['attributes']['styling'] = array(
    '#type' => 'markup',
    '#value' => '
        <p>' . t('Any fields that you add to this view will be attached to their respective feature (point, line, polygon) as attributes.  These attributes can then be used to add variable styling to your themes.  This is accomplished by using the %syntax syntax in the values for a style.  The following is a list of formatted variables that are currently available; these can be placed right in the style interface.  The %rendered one means that it has been processed by Views and may have a different value.', array(
      '%syntax' => '${field_name}',
      '%rendered' => '_rendered',
    )) . '</p>
        ' . theme('item_list', $variable_fields) . '
        <p>' . t('Please note that this does not apply to Grouped Displays.') . '</p>
      ',
  );
}