You are here

private function ScheduledPublishCron::updateNodeField in Scheduled Publish 8

1 call to ScheduledPublishCron::updateNodeField()
ScheduledPublishCron::doUpdate in src/Service/ScheduledPublishCron.php

File

src/Service/ScheduledPublishCron.php, line 85

Class

ScheduledPublishCron
Class ScheduledPublishCron

Namespace

Drupal\scheduled_publish\Service

Code

private function updateNodeField(Node $node, string $scheduledField) : void {

  /** @var FieldItemList $scheduledEntity */
  $scheduledEntity = $node
    ->get($scheduledField);
  $scheduledValue = $scheduledEntity
    ->getValue();
  if (empty($scheduledValue)) {
    return;
  }
  $currentModerationState = $node
    ->get('moderation_state')
    ->getValue()[0]['value'];
  $scheduledEntityStore = $scheduledValue;
  if ($currentModerationState === $scheduledEntityStore[0]['moderation_state']) {
    $this
      ->updateNode($node, $scheduledEntityStore[0]['moderation_state'], $scheduledField);
    return;
  }
  $timestamp = $this
    ->getTimestampFromIso8601($scheduledEntityStore[0]['value']);
  if ($timestamp - $this->dateTime
    ->getCurrentTime() <= 0) {
    $this
      ->updateNode($node, $scheduledEntityStore[0]['moderation_state'], $scheduledField);
  }
}