function tmgmt_content_entity_update

Implements hook_entity_update().

File

sources/content/tmgmt_content.module, line 297
Source plugin for the Translation Management system that handles entities.

Code

function tmgmt_content_entity_update(EntityInterface $entity) {
  if ($entity instanceof ContentEntityInterface && $entity
    ->isTranslatable() && !$entity
    ->getEntityType()
    ->get('entity_revision_parent_type_field')) {
    $entity = $entity
      ->getUntranslated();
    $source_langcode = $entity
      ->language()
      ->getId();
    $current_job_items = tmgmt_job_item_load_latest('content', $entity
      ->getEntityTypeId(), $entity
      ->id(), $source_langcode);
    if ($current_job_items) {

      /** @var \Drupal\tmgmt\JobItemInterface $job_item */
      foreach ($current_job_items as $job_item) {

        // If the job item is not yet submitted update its data.
        if ($job_item
          ->getJob()
          ->isSubmittable() || $job_item
          ->isInactive()) {
          $job_item
            ->resetData();
          $job_item
            ->addMessage('Updated source data.');
        }
        elseif ($job_item
          ->getJob()
          ->isContinuous()) {
          $continuous_manager = \Drupal::service('tmgmt.continuous');
          $continuous_manager
            ->addItem($job_item
            ->getJob(), 'content', $entity
            ->getEntityTypeId(), $entity
            ->id());
        }
      }
    }
    tmgmt_content_create_continuous_job_items($entity);
  }
}