You are here

function _ip_geoloc_plugin_style_diff_color_table_row_form in IP Geolocation Views & Maps 7

Same name and namespace in other branches
  1. 8 src/Plugin/views/style/ip_geoloc_plugin_style.inc \_ip_geoloc_plugin_style_diff_color_table_row_form()

Diffs the color table plugin style row.

1 call to _ip_geoloc_plugin_style_diff_color_table_row_form()
_ip_geoloc_plugin_style_differentiator_color_table_form in views/ip_geoloc_plugin_style.inc
Plugin style color differ.

File

views/ip_geoloc_plugin_style.inc, line 425
ip_geoloc_plugin_style.inc

Code

function _ip_geoloc_plugin_style_diff_color_table_row_form($is_openlayers, $row, $differentiator, $association = NULL) {
  $differentiator_value = empty($association) ? NULL : $association['differentiator_value'];
  $attr_class = $is_openlayers ? array(
    'differentiator ol',
  ) : array(
    'differentiator',
  );
  if (strpos($differentiator, 'field_') === 0) {
    $field = field_info_field($differentiator);
    $instances = ip_geoloc_get_field_instances($differentiator);
    $instance = reset($instances);
    $widget = $instance['widget']['type'];
    if (strpos($widget, 'taxonomy') !== FALSE) {

      // Covers core and Autocomplete Deluxe.
      $vid = 0;
      $vocabulary_name = $field['settings']['allowed_values'][0]['vocabulary'];
      foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
        if ($vocabulary->machine_name == $vocabulary_name) {
          break;
        }
      }
      $options = array();
      foreach (taxonomy_get_tree($vid) as $term) {
        $options[$term->tid] = str_repeat('-', $term->depth) . $term->name;
      }
      $form[$differentiator] = array(
        '#type' => empty($options) ? 'textfield' : 'select',
        '#options' => $options,
        '#default_value' => $differentiator_value,
        '#attributes' => array(
          'class' => $attr_class,
        ),
      );
    }
    else {

      // No label, unless other modules override this.
      $instance['label'] = '';

      // Don't want asterisk to appear.
      $instance['required'] = FALSE;

      // Make sure the text field is wide enough, especially for the case of a
      // range, which needs to receive two values and a separator.
      if (isset($instance['widget']['settings']['size']) && $instance['widget']['settings']['size'] < 15) {
        $instance['widget']['settings']['size'] = 15;
      }
      $items[0] = empty($differentiator_value) ? array() : is_array($differentiator_value) ? $differentiator_value : array(
        $differentiator_value,
      );
      if (isset($instance['default_value'])) {
        $items[0] += is_array($instance['default_value']) && !empty($instance['default_value']) ? reset($instance['default_value']) : $instance['default_value'];
      }
      $form['#parents'] = array();
      $form_state = array();
      $form = field_default_form($instance['entity_type'], NULL, $field, $instance, LANGUAGE_NONE, $items, $form, $form_state);
      if ($field['module'] == 'number' || $field['module'] == 'text') {
        $form[$differentiator][LANGUAGE_NONE][0][key($field['columns'])]['#element_validate'] = array(
          'ip_geoloc_range_widget_validate',
        );
      }
      $form[$differentiator]['#attributes']['class'][] = $attr_class;
    }
  }
  else {

    // Not a field, maybe an expression. Or a taxonomy term NOT wrapped in a
    // field, e.g., 'taxonomy_term_data_name'.
    if (ip_geoloc_is_taxonomy_term($differentiator)) {

      // The problem is that we don't know for sure the vocabulary...
      // So we cannot produce a drop-down select with all terms...
      // Fall back on textfield.
    }
    $form[$differentiator] = array(
      '#type' => 'textfield',
      '#size' => 40,
      '#default_value' => $differentiator_value,
      '#element_validate' => array(
        'ip_geoloc_range_widget_validate',
      ),
      '#attributes' => array(
        'class' => $attr_class,
      ),
    );
  }
  $form['color'] = array(
    '#type' => 'select',
    '#default_value' => empty($association) ? NULL : $association['color'],
    '#options' => $is_openlayers ? ip_geoloc_openlayers_marker_layers() : ip_geoloc_marker_colors(),
    '#attributes' => array(
      'class' => $is_openlayers ? array(
        'marker-color-ol',
      ) : array(
        'marker-color',
      ),
    ),
  );
  $form['special char'] = array(
    '#type' => 'textfield',
    '#size' => 8,
    '#default_value' => empty($association) ? NULL : $association['special char'],
  );
  $form['special char class'] = array(
    '#type' => 'textfield',
    '#size' => 25,
    '#default_value' => empty($association) ? NULL : $association['special char class'],
  );

  // We'll manually set the #parents property of these fields so that their
  // values appear in the $form_state['values']['color_table'] array.
  $form[$differentiator]['#parents'] = array(
    'color_table',
    $row,
    $differentiator,
  );
  $form['color']['#parents'] = array(
    'color_table',
    $row,
    'color',
  );
  $form['special char']['#parents'] = array(
    'color_table',
    $row,
    'special char',
  );
  $form['special char class']['#parents'] = array(
    'color_table',
    $row,
    'special char class',
  );
  return $form;
}