You are here

function salesforce_push_entity_crud in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 modules/salesforce_push/salesforce_push.module \salesforce_push_entity_crud()
  2. 7.3 modules/salesforce_push/salesforce_push.module \salesforce_push_entity_crud()
  3. 5.0.x modules/salesforce_push/salesforce_push.module \salesforce_push_entity_crud()

Push entities to Salesforce.

@TODO at some point all these hook_entity_* implementations will go away. We'll create an event subscriber class to respond to entity events and delegate actions to the appropriate Push procedures. Unfortunately this point seems to be a very long ways away. https://www.drupal.org/node/2551893

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object.

string $op: The trigger being responded to. One of push_create, push_update, push_delete.

5 calls to salesforce_push_entity_crud()
drush_salesforce_push_unmapped in modules/salesforce_push/salesforce_push.drush.inc
Implements drush_hook_COMMAND().
SalesforcePushCommands::pushUnmapped in modules/salesforce_push/src/Commands/SalesforcePushCommands.php
Push entities of a mapped type that are not linked to Salesforce Objects.
salesforce_push_entity_delete in modules/salesforce_push/salesforce_push.module
Implements hook_entity_delete().
salesforce_push_entity_insert in modules/salesforce_push/salesforce_push.module
Implements hook_entity_insert().
salesforce_push_entity_update in modules/salesforce_push/salesforce_push.module
Implements hook_entity_update().

File

modules/salesforce_push/salesforce_push.module, line 54
Push updates to Salesforce when a Drupal entity is updated.

Code

function salesforce_push_entity_crud(EntityInterface $entity, $op) {

  // Don't allow mapped objects or mappings to be pushed!
  if (!empty($entity->salesforce_pull) || $entity instanceof MappedObjectInterface || $entity instanceof SalesforceMappingInterface) {
    return;
  }
  $properties = [];
  if ($entity_type = $entity
    ->getEntityTypeId()) {
    $properties['drupal_entity_type'] = $entity_type;
  }
  if ($bundle = $entity
    ->bundle()) {
    $properties['drupal_bundle'] = $bundle;
  }

  /** @var \Drupal\salesforce_mapping\Entity\SalesforceMapping[] $mappings */
  $mappings = \Drupal::service('entity_type.manager')
    ->getStorage('salesforce_mapping')
    ->loadPushMappingsByProperties($properties);
  if (empty($mappings)) {
    return;
  }
  foreach ($mappings as $mapping) {
    if (!$mapping
      ->checkTriggers([
      $op,
    ])) {
      continue;
    }
    try {
      salesforce_push_entity_crud_mapping($entity, $op, $mapping);
    } catch (\Exception $e) {

      // Do not allow any exception to prevent entity CRUD.
      \Drupal::service('event_dispatcher')
        ->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e));
    }
  }
}