You are here

public function ServicesClientPropertyFormatter::format in Services Client 7.2

Format source value to destination.

Parameters

ServicesClientMappingValue $source: Source value gathered from Reader.

Return value

array Value specified by 'key' => 'name', 'value' => 'mixed'

Overrides ServicesClientMappingFormatterInterface::format

File

include/mapping.inc, line 536

Class

ServicesClientPropertyFormatter
Formats data to property.

Code

public function format(ServicesClientMappingValue $source) {

  // Handle empty values
  if ($source
    ->isEmpty()) {
    if ($this->config['empty'] == 'no_field') {
      return NULL;
    }
    elseif ($this->config['empty'] == 'null_field') {
      return array(
        'key' => $this->config['property'],
        'value' => NULL,
      );
    }
    elseif ($this->config['empty'] == 'default_value') {
      return array(
        'key' => $this->config['property'],
        'value' => $this->config['default_value'],
      );
    }
  }

  // If single value is forced.
  $value = $source
    ->getValue();
  if ($this->config['multivalue'] == 'force_single') {
    $value = reset($value);
  }

  // Return resulting value.
  return array(
    'key' => $this->config['property'],
    'value' => $value,
  );
}