You are here

public function ScheduledTransitionsTokenReplacements::getReplacements in Scheduled Transitions 2.x

Get variables for translation or replacement.

Return value

array An array of strings keyed by replacement key.

File

src/ScheduledTransitionsTokenReplacements.php, line 77

Class

ScheduledTransitionsTokenReplacements
Represents strings used as replacement variables in translation or logger.

Namespace

Drupal\scheduled_transitions

Code

public function getReplacements() {
  if (isset($this->cachedReplacements)) {
    return $this->cachedReplacements;
  }
  $entityRevisionId = $this->newRevision
    ->getRevisionId();

  // getWorkflowForEntity only supports Content Entities, this can be removed
  // if Scheduled Transitions supports non CM workflows in the future.
  if ($this->latest instanceof ContentEntityInterface) {
    $workflow = $this
      ->moderationInformation()
      ->getWorkflowForEntity($this->latest);
    $workflowPlugin = $workflow
      ->getTypePlugin();
    $states = $workflowPlugin
      ->getStates();
  }
  $originalNewRevisionState = $states[$this->newRevision->moderation_state->value ?? ''] ?? NULL;
  $originalLatestState = $states[$this->latest->moderation_state->value ?? ''] ?? NULL;
  $newState = $states[$this->scheduledTransition
    ->getState()] ?? NULL;
  return $this->cachedReplacements = [
    'from-revision-id' => $entityRevisionId,
    'from-state' => $originalNewRevisionState ? $originalNewRevisionState
      ->label() : $this
      ->t('- Unknown state -'),
    'to-state' => $newState ? $newState
      ->label() : $this
      ->t('- Unknown state -'),
    'latest-revision-id' => $this->latest
      ->getRevisionId(),
    'latest-state' => $originalLatestState ? $originalLatestState
      ->label() : $this
      ->t('- Unknown state -'),
  ];
}