You are here

protected function UpdateRunnerUtils::entityUpdatesChanged in Scheduled Updates 8

Check to see if Updates attached to an entity has changed.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity:

\Drupal\scheduled_updates\Plugin\EntityMonitorUpdateRunnerInterface $runner:

Return value

bool

1 call to UpdateRunnerUtils::entityUpdatesChanged()
UpdateRunnerUtils::invokeEntityUpdate in src/UpdateRunnerUtils.php

File

src/UpdateRunnerUtils.php, line 175
Contains \Drupal\scheduled_updates\UpdateRunnerUtils.

Class

UpdateRunnerUtils
A service that runs all available updaters

Namespace

Drupal\scheduled_updates

Code

protected function entityUpdatesChanged(ContentEntityInterface $entity, EntityMonitorUpdateRunnerInterface $runner) {

  // We can't use $entity->original because it is not always the last revision.

  /** @var ContentEntityInterface $previous */
  if ($entity
    ->getEntityType()
    ->isRevisionable()) {
    $previous = $this->updateUtils
      ->getPreviousRevision($entity);
  }
  else {
    $previous = isset($entity->original) ? $entity->original : NULL;
  }
  if ($previous) {
    $field_ids = $runner
      ->getReferencingFieldIds();
    foreach ($field_ids as $field_id) {
      $previous_update_ids = $runner
        ->getEntityReferenceTargetIds($previous, $field_id, TRUE);
      $updated_update_ids = $runner
        ->getEntityReferenceTargetIds($entity, $field_id, TRUE);
      if ($previous_update_ids != $updated_update_ids) {
        return TRUE;
      }
    }
  }
  return FALSE;
}