You are here

public function IpGeoLocViewsPluginStyle::pluginStyleDifferentiatorColorTableForm in IP Geolocation Views & Maps 8

Plugin style color differ.

1 call to IpGeoLocViewsPluginStyle::pluginStyleDifferentiatorColorTableForm()
IpGeoLocViewsPluginStyle::pluginStyleBulkOfForm in src/Services/IpGeoLocViewsPluginStyle.php
The bulk of the plugin style form.

File

src/Services/IpGeoLocViewsPluginStyle.php, line 447

Class

IpGeoLocViewsPluginStyle
Class IpGeoLocViewsPluginStyle.

Namespace

Drupal\ip_geoloc\Services

Code

public function pluginStyleDifferentiatorColorTableForm(&$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.
  $view_id = $form_state
    ->get('view')
    ->get('storage')
    ->get('id');
  $display_id = $form_state
    ->get('display_id');
  $differentiator = $form_state
    ->get('differentiator');
  $differentiator_color_associations = $this->config
    ->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 ($form_state
      ->has('num_associations') && $row >= $form_state
      ->get('num_associations')) {
      break;
    }
    $form['differentiator']['color_table'][$row] = $this
      ->pluginStyleDiffColorTableRowForm($is_openlayers, $row, $differentiator, $association);

    //$form['differentiator']['color_table']['#rows'][$row] = $this->pluginStyleDiffColorTableRowForm($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]));
    if (empty($differentiator_color_associations[$display_id][$differentiator])) {
      $form_state
        ->set('num_associations', count($differentiator_color_associations[$display_id]));
    }
    else {
      $form_state
        ->set('num_associations', count($differentiator_color_associations[$display_id][$differentiator]));
    }
  }
  while ($row < $form_state
    ->get('num_associations')) {
    $form['differentiator']['color_table'][$row] = $this
      ->pluginStyleDiffColorTableRowForm($is_openlayers, $row, $differentiator);

    //$form['differentiator']['color_table']['#rows'][$row] = $this->pluginStyleDiffColorTableRowForm($is_openlayers, $row, $differentiator);
    $row++;
  }
}