You are here

protected function ScheduledPublishCron::isValidStateChange in Scheduled Publish 8.3

Checks if the state change is valid.

Parameters

\Drupal\Core\Entity\ContentEntityBase $entity:

string $moderationState:

Return value

boolean

1 call to ScheduledPublishCron::isValidStateChange()
ScheduledPublishCron::updateEntity in src/Service/ScheduledPublishCron.php
Updates entity

File

src/Service/ScheduledPublishCron.php, line 236

Class

ScheduledPublishCron
Class ScheduledPublishCron

Namespace

Drupal\scheduled_publish\Service

Code

protected function isValidStateChange(ContentEntityBase $entity, string $moderationState) : bool {
  $workflow = $this->moderationInfo
    ->getWorkflowForEntity($entity);
  $current_state = $entity->moderation_state->value ? $workflow
    ->getTypePlugin()
    ->getState($entity->moderation_state->value) : $workflow
    ->getTypePlugin()
    ->getInitialState($entity);
  $transitions = $current_state
    ->getTransitions();
  foreach ($transitions as $key => $value) {
    if ($value
      ->to()
      ->id() === $moderationState) {
      return TRUE;
    }
  }
  return FALSE;
}