You are here

public function LingotekContentTranslationService::hasEntityChanged in Lingotek Translation 3.3.x

Same name and namespace in other branches
  1. 8 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  2. 8.2 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  3. 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  4. 3.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  5. 3.1.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged()
  6. 3.2.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

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

Overrides LingotekContentTranslationServiceInterface::hasEntityChanged

File

src/LingotekContentTranslationService.php, line 770

Class

LingotekContentTranslationService
Service for managing Lingotek content translations.

Namespace

Drupal\lingotek

Code

public function hasEntityChanged(ContentEntityInterface &$entity) {
  if (isset($entity->original)) {
    if ($entity
      ->getRevisionId() !== $entity->original
      ->getRevisionId()) {
      return TRUE;
    }
    $source_data = $this
      ->getSourceData($entity);
    if (isset($source_data['_lingotek_metadata'])) {
      unset($source_data['_lingotek_metadata']['_entity_revision']);
    }
    $source_data = json_encode($source_data);
    $hash = md5($source_data);
    $old_source_data = $this
      ->getSourceData($entity->original);
    if (isset($old_source_data['_lingotek_metadata'])) {
      unset($old_source_data['_lingotek_metadata']['_entity_revision']);
    }
    $old_source_data = json_encode($old_source_data);
    $old_hash = md5($old_source_data);
    return (bool) strcmp($hash, $old_hash);
  }
  else {
    return TRUE;
  }
}