You are here

public function LingotekContentTranslationService::hasEntityChanged in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  2. 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  3. 3.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  4. 3.1.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  5. 3.2.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  6. 3.3.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  7. 3.4.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  8. 3.5.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  9. 3.6.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  10. 3.7.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  11. 3.8.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()

Checks if the source entity data has changed from last time we uploaded it.

Parameters

\Drupal\Core\Entity\ContentEntityInterface &$entity: The entity being checked

Return value

boolean TRUE if the entity has changed, false if not.

Overrides LingotekContentTranslationServiceInterface::hasEntityChanged

File

src/LingotekContentTranslationService.php, line 519
Contains \Drupal\lingotek\LingotekContentTranslationService.

Class

LingotekContentTranslationService
Service for managing Lingotek content translations.

Namespace

Drupal\lingotek

Code

public function hasEntityChanged(ContentEntityInterface &$entity) {

  // Perform the cheapest checks first.
  if (isset($entity->original)) {
    return $entity->lingotek_hash->value !== $entity->original->lingotek_hash->value;
  }

  // The following code should not be called very often, if at all.
  $old_hash = $entity->lingotek_hash->value;
  if (!$old_hash) {
    return TRUE;
  }
  $source_data = json_encode($this
    ->getSourceData($entity));
  $hash = md5($source_data);
  return (bool) strcmp($hash, $old_hash);
}