You are here

function IpGeoLocViewsPluginStyle::pluginStyleGetSearchApiValue in IP Geolocation Views & Maps 8

1 call to IpGeoLocViewsPluginStyle::pluginStyleGetSearchApiValue()
IpGeoLocViewsPluginStyle::getViewResult in src/Services/IpGeoLocViewsPluginStyle.php
Returns as an array the raw value(s) of a field in the results set.

File

src/Services/IpGeoLocViewsPluginStyle.php, line 1268

Class

IpGeoLocViewsPluginStyle
Class IpGeoLocViewsPluginStyle.

Namespace

Drupal\ip_geoloc\Services

Code

function pluginStyleGetSearchApiValue($row, $field_name) {
  $field_value = null;
  if (isset($row->_entity_properties[$field_name])) {

    //drupal_set_message(t('IPGV&M (1): Search API checking value for %name', array('%name' => $field_name)), 'warning', FALSE);
    $field_value = $row->_entity_properties[$field_name];
  }
  elseif ($last_ = strrpos($field_name, '_')) {
    $alt_field_name = Unicode::substr($field_name, $last_ + 1);

    //drupal_set_message(t('IPGV&M (2): Search API checking value for %name', array('%name' => $alt_field_name)), 'warning', FALSE);
    if (isset($row->_entity_properties[$alt_field_name])) {
      $field_value = $row->_entity_properties[$alt_field_name];
    }
  }
  else {
    $alt_field_name = 'field_' . $field_name;

    //drupal_set_message(t('IPGV&M (3): Search API checking value for %name', array('%name' => $alt_field_name)), 'warning', FALSE);
    if (isset($row->_entity_properties[$alt_field_name])) {
      $field_value = $row->_entity_properties[$alt_field_name];
    }
  }
  if (isset($field_value)) {

    //drupal_set_message(t('IPGV&M (success!): Search API %name=%value', array('%name' => $field_name, '%value' => $field_value)), 'warning', FALSE);
  }
  else {
    $this
      ->messenger($this->stringTranslation
      ->translate('IPGV&M: Could not retrieve value of field %name, as its name does not appear among these Search API keys: %keys', array(
      '%name' => $field_name,
      '%keys' => implode(', ', array_keys($row->_entity_properties)),
    )), 'warning', FALSE);
  }
  return isset($field_value) ? $field_value : '';
}