You are here

protected function Rest::getMappedObject in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 modules/salesforce_push/src/Plugin/SalesforcePushQueueProcessor/Rest.php \Drupal\salesforce_push\Plugin\SalesforcePushQueueProcessor\Rest::getMappedObject()
  2. 5.0.x modules/salesforce_push/src/Plugin/SalesforcePushQueueProcessor/Rest.php \Drupal\salesforce_push\Plugin\SalesforcePushQueueProcessor\Rest::getMappedObject()

Return the mapped object given a queue item and mapping.

Parameters

object $item: Push queue item.

\Drupal\salesforce_mapping\Entity\SalesforceMappingInterface $mapping: The mapping.

Return value

\Drupal\salesforce_mapping\Entity\MappedObject The mapped object.

1 call to Rest::getMappedObject()
Rest::processItem in modules/salesforce_push/src/Plugin/SalesforcePushQueueProcessor/Rest.php
Push queue item process callback.

File

modules/salesforce_push/src/Plugin/SalesforcePushQueueProcessor/Rest.php, line 212

Class

Rest
Rest queue processor plugin.

Namespace

Drupal\salesforce_push\Plugin\SalesforcePushQueueProcessor

Code

protected function getMappedObject(\stdClass $item, SalesforceMappingInterface $mapping) {
  $mapped_object = FALSE;

  // Prefer mapped object id if we have one.
  if ($item->mapped_object_id) {
    $mapped_object = $this->mappedObjectStorage
      ->load($item->mapped_object_id);
  }
  if ($mapped_object) {
    return $mapped_object;
  }

  // Fall back to entity+mapping, which is a unique key.
  if ($item->entity_id) {
    $mapped_object = $this->mappedObjectStorage
      ->loadByProperties([
      'drupal_entity__target_type' => $mapping->drupal_entity_type,
      'drupal_entity__target_id' => $item->entity_id,
      'salesforce_mapping' => $mapping
        ->id(),
    ]);
  }
  if ($mapped_object) {
    if (is_array($mapped_object)) {
      $mapped_object = current($mapped_object);
    }
    return $mapped_object;
  }
  return $this
    ->createMappedObject($item, $mapping);
}