You are here

function salesforce_mapping_entity_update in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 modules/salesforce_mapping/salesforce_mapping.module \salesforce_mapping_entity_update()
  2. 8.3 modules/salesforce_mapping/salesforce_mapping.module \salesforce_mapping_entity_update()
  3. 7.3 modules/salesforce_mapping/salesforce_mapping.module \salesforce_mapping_entity_update()

Implements hook_entity_update().

Ensures drupal entity has an update timestamp.

File

modules/salesforce_mapping/salesforce_mapping.module, line 15
Manages Salesforce object and Drupal entity mappings.

Code

function salesforce_mapping_entity_update(EntityInterface $entity) {

  // Check for mappings (much faster than looking for mapped objects.)
  $mappings = \Drupal::service('entity_type.manager')
    ->getStorage('salesforce_mapping')
    ->loadByDrupal($entity
    ->getEntityTypeId());
  if (empty($mappings)) {
    return;
  }

  // If mappings, check for mapped objects.
  $mapped_objects = \Drupal::service('entity_type.manager')
    ->getStorage('salesforce_mapped_object')
    ->loadByDrupal($entity
    ->getEntityTypeId(), $entity
    ->id());
  foreach ($mapped_objects as $mapped_object) {

    // Resaving the object should update the timestamp.
    // NB: we are purposefully not creating a new revision here.
    $mapped_object
      ->set('entity_updated', \Drupal::time()
      ->getRequestTime())
      ->save();
  }
}