You are here

function _ip_geoloc_plugin_style_set_marker_color 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_set_marker_color()

Set the marker color.

1 call to _ip_geoloc_plugin_style_set_marker_color()
ip_geoloc_plugin_style_extract_locations in src/Plugin/views/style/ip_geoloc_plugin_style.inc
Extract an array of locations from the supplied views_plugin_style.

File

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

Code

function _ip_geoloc_plugin_style_set_marker_color(&$location, $row, $differentiator, $differentiator_color_associations) {
  if (!empty($differentiator)) {
    if (!empty($row->{$differentiator})) {
      $differentiator_value = $row->{$differentiator};
    }
    elseif (!empty($row->{'field_' . $differentiator})) {
      $differentiator_values = $row->{'field_' . $differentiator};
      if (is_array($differentiator_values)) {

        // Count > 1 for taxonomy term with lineage.
        $num_values = count($differentiator_values);
        if (isset($differentiator_values[0]['raw'])) {
          $differentiator_value = $differentiator_values[$num_values - 1]['raw'];
        }
        elseif (isset($differentiator_values[0]['rendered']['#markup'])) {
          $differentiator_value = $differentiator_values[$num_values - 1]['rendered']['#markup'];
        }
      }
    }
    else {
      $differentiator_value = '';
      if (!isset($row->{'field_' . $differentiator})) {
        drupal_set_message(t('IPGV&M: no differentiator values found for %diff. Cannot set marker images.', [
          '%diff' => $differentiator,
        ]), 'warning', FALSE);
      }
    }
    if (!empty($differentiator_value)) {
      foreach ($differentiator_color_associations as $association) {
        $match = TRUE;
        if (is_array($differentiator_value)) {
          if (empty($differentiator_value['tid'])) {

            // Eg AddressField, has multiple subvalues. All must match the
            // corresponding differentiator subvalues.
            foreach ($association['differentiator_value'] as $name => $subvalue) {
              if (!isset($differentiator_value[$name]) || !ip_geoloc_is_in_range($differentiator_value[$name], $subvalue)) {
                $match = FALSE;
                break;
              }
            }
          }
          else {

            // 'tid' set: taxonomy widget (plain or autocomplete)
            // $association['differentiator_value'] can have index 0 or 'tid'.
            $range = reset($association['differentiator_value']);
            $match = ip_geoloc_is_in_range($differentiator_value['tid'], $range);
          }
        }
        else {

          // Single value, either as simple value or array of length 1.
          $range = $association['differentiator_value'];
          $match = ip_geoloc_is_in_range($differentiator_value, $range);
        }
        if ($match) {
          $location->marker_color = $association['color'];
          if (!empty($association['special char'])) {
            $location->marker_special_char = $association['special char'];
          }
          if (!empty($association['special char class'])) {
            $location->marker_special_char_class = $association['special char class'];
          }
        }
      }
    }
  }
  if (isset($location->marker_color) && is_array($location->marker_color)) {
    $location->marker_color = reset($location->marker_color);
  }
}