You are here

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

Submit handler as declared in ip_geoloc_form_alter().

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

File

src/Services/IpGeoLocViewsPluginStyle.php, line 386

Class

IpGeoLocViewsPluginStyle
Class IpGeoLocViewsPluginStyle.

Namespace

Drupal\ip_geoloc\Services

Code

public function pluginStyleDifferentiatorColorAssociationsSubmit(&$form, &$form_state) {
  if (empty($form_state
    ->get('view')) || empty($form_state
    ->get('display_id')) || empty($form_state
    ->get('differentiator'))) {
    return;
  }
  $view_id = $form_state
    ->get('view')
    ->get('storage')
    ->get('id');
  $display_id = $form_state
    ->get('display_id');
  $differentiator = $form_state
    ->get('differentiator');

  // Erase differentiator values for this display, then rebuild based on form.
  $differentiator_color_associations = $this->config
    ->get('ip_geoloc_' . $view_id . '_color_mappings', []);
  unset($differentiator_color_associations[$display_id][$differentiator]);
  $user_input = $form_state
    ->getUserInput();
  if (!empty($user_input['color_table'])) {
    $i = 0;
    foreach ($user_input['color_table'] as $association) {
      if (is_array($association[$differentiator])) {

        // E.g association['field_address']['und'][0]['postal_code'].
        foreach ($association[$differentiator][LANGUAGE_NONE] as $values) {
          $differentiator_value = [];
          if (is_array($values)) {
            foreach ($values as $name => $value) {
              if (isset($value) && strpos($value, '|') === FALSE) {
                $differentiator_value[$name] = $value;
              }
            }
          }
          else {
            $differentiator_value[] = $values;
          }
          if (!empty($differentiator_value)) {
            $differentiator_color_associations[$display_id][$differentiator][$i]['differentiator_value'] = $differentiator_value;
            $differentiator_color_associations[$display_id][$differentiator][$i]['color'] = $association['color'];
            $differentiator_color_associations[$display_id][$differentiator][$i]['special char'] = $association['special char'];
            $differentiator_color_associations[$display_id][$differentiator][$i]['special char class'] = $association['special char class'];
            $i++;
          }
        }
      }
      else {

        // Plain text field or plain taxonomy select.
        $differentiator_value = trim($association[$differentiator]);
        if (!empty($differentiator_value)) {
          $differentiator_color_associations[$display_id][$differentiator][$i]['differentiator_value'] = [
            $differentiator_value,
          ];
          $differentiator_color_associations[$display_id][$differentiator][$i]['color'] = $association['color'];
          $differentiator_color_associations[$display_id][$differentiator][$i]['special char'] = $association['special char'];
          $differentiator_color_associations[$display_id][$differentiator][$i]['special char class'] = $association['special char class'];
          $i++;
        }
      }
    }
  }
  $this->config
    ->set('ip_geoloc_' . $view_id . '_color_mappings', $differentiator_color_associations)
    ->save();
}