You are here

function _ip_geoloc_plugin_style_differentiator_color_table_form in IP Geolocation Views & Maps 8

Same name and namespace in other branches
  1. 7 views/ip_geoloc_plugin_style.inc \_ip_geoloc_plugin_style_differentiator_color_table_form()

Plugin style color differ.

File

src/Plugin/views/style/ip_geoloc_plugin_style.inc, line 369
ip_geoloc_plugin_style.inc

Code

function _ip_geoloc_plugin_style_differentiator_color_table_form(&$form, FormStateInterface &$form_state) {
  $is_openlayers = $form_state
    ->get('renderer') == 'openlayers';

  // First the saved rows...
  // @todo: if $field['cardinality'] > 1, compress multiple diff. values
  // for the same color together in a single row.

  //@TODO Check if this works
  $view_id = $form_state
    ->get('view')->name;
  $display_id = $form_state
    ->get('display_id');
  $differentiator = $form_state
    ->get('differentiator');
  $differentiator_color_associations = \Drupal::state()
    ->get('ip_geoloc_' . $view_id . '_color_mappings', []);
  if (empty($differentiator_color_associations[$display_id][$differentiator])) {
    $differentiator_color_associations[$display_id] = [
      $differentiator => [],
    ];
  }
  $row = 0;
  foreach ($differentiator_color_associations[$display_id][$differentiator] as $association) {
    if (!is_array($association)) {

      // Data corrupt.
      break;
    }
    if (!empty($form_state
      ->get('num_associations')) && $row >= $form_state
      ->get('num_associations')) {
      break;
    }
    $form['differentiator']['color_table'][$row] = _ip_geoloc_plugin_style_diff_color_table_row_form($is_openlayers, $row, $differentiator, $association);
    $row++;
  }

  // ... then the empty rows.
  if (!$form_state
    ->has('num_associations')) {
    $form_state
      ->set('num_associations', count($differentiator_color_associations[$display_id][$differentiator]));
  }
  while ($row < $form_state
    ->get('num_associations')) {
    $form['differentiator']['color_table'][$row] = _ip_geoloc_plugin_style_diff_color_table_row_form($is_openlayers, $row, $differentiator);
    $row++;
  }
}