You are here

protected function EntitySaveHandler::getMappedObject in Services Client 7.2

Retrieve object that should be send to remote site.

Return value

stdClass Mapped object.

1 call to EntitySaveHandler::getMappedObject()
EntitySaveHandler::execute in include/event.inc
Execute event and send event to remove endpoint.

File

include/event.inc, line 892

Class

EntitySaveHandler
General entity save handler.

Code

protected function getMappedObject() {
  $entity = $this
    ->getEntity();
  $mapped = new stdClass();
  foreach ($this->config['mapping'] as $uuid => $plugin) {
    try {
      $handler = $this
        ->getPluginInstance($plugin['type'], $plugin['config'], $uuid);
      $source = $handler
        ->getReader()
        ->read($entity);
      if (!empty($source)) {
        $formatted = $handler
          ->getFormatter()
          ->format($source);
        if (!empty($formatted['key'])) {

          // Merge fields
          if (isset($mapped->{$formatted['key']}) && is_array($mapped->{$formatted['key']})) {
            $mapped->{$formatted['key']} = array_replace_recursive($mapped->{$formatted['key']}, $formatted['value']);
          }
          else {
            $mapped->{$formatted['key']} = $formatted['value'];
          }
        }
      }
    } catch (Exception $e) {
      watchdog_exception('services_client', $e);
    }
  }

  // Automatically map UUIDs
  if (isset($entity->uuid) && !isset($mapped->uuid)) {
    $mapped->uuid = $entity->uuid;
  }
  $this
    ->log(ServicesClientLogLevel::DEVEL, "MAPPED DATA; source : <pre>@source</pre>, mapped: <pre>@mapped</pre>", array(
    '@source' => $this
      ->debugObject($entity),
    '@mapped' => $this
      ->debugObject($mapped),
  ));
  return $mapped;
}