You are here

private function ScheduledPublishCron::updateEntity in Scheduled Publish 8.3

Same name and namespace in other branches
  1. 8.2 src/Service/ScheduledPublishCron.php \Drupal\scheduled_publish\Service\ScheduledPublishCron::updateEntity()

Updates entity

Parameters

\Drupal\Core\Entity\ContentEntityBase $entity:

string $moderationState:

string $scheduledPublishField:

$scheduledValue:

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to ScheduledPublishCron::updateEntity()
ScheduledPublishCron::updateEntityField in src/Service/ScheduledPublishCron.php
Update scheduled publish fields

File

src/Service/ScheduledPublishCron.php, line 209

Class

ScheduledPublishCron
Class ScheduledPublishCron

Namespace

Drupal\scheduled_publish\Service

Code

private function updateEntity(ContentEntityBase $entity, string $moderationState, string $scheduledPublishField, $scheduledValue) : void {
  $entity
    ->set($scheduledPublishField, $scheduledValue);

  // Only make valid transitions.
  if ($this
    ->isValidStateChange($entity, $moderationState)) {
    $currentModerationState = $entity
      ->get('moderation_state')
      ->getValue()[0]['value'];
    $entity
      ->set('moderation_state', $moderationState);
  }
  $entity
    ->save();

  // Log valid transitions.
  if (isset($currentModerationState)) {
    $entity_info = $entity
      ->label() . ' (' . $entity
      ->id() . ')';
    $this->logger
      ->get('scheduled_publish')
      ->info('The moderation state of @entity was changed from @orig_status to @current_status', [
      '@entity' => $entity_info,
      '@orig_status' => $currentModerationState,
      '@current_status' => $moderationState,
    ]);
  }
}