You are here

public function LingotekContentModerationHandler::performModerationTransitionIfNeeded in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 8.2 src/Moderation/LingotekContentModerationHandler.php \Drupal\lingotek\Moderation\LingotekContentModerationHandler::performModerationTransitionIfNeeded()
  2. 3.0.x src/Moderation/LingotekContentModerationHandler.php \Drupal\lingotek\Moderation\LingotekContentModerationHandler::performModerationTransitionIfNeeded()
  3. 3.1.x src/Moderation/LingotekContentModerationHandler.php \Drupal\lingotek\Moderation\LingotekContentModerationHandler::performModerationTransitionIfNeeded()
  4. 3.2.x src/Moderation/LingotekContentModerationHandler.php \Drupal\lingotek\Moderation\LingotekContentModerationHandler::performModerationTransitionIfNeeded()
  5. 3.3.x src/Moderation/LingotekContentModerationHandler.php \Drupal\lingotek\Moderation\LingotekContentModerationHandler::performModerationTransitionIfNeeded()
  6. 3.4.x src/Moderation/LingotekContentModerationHandler.php \Drupal\lingotek\Moderation\LingotekContentModerationHandler::performModerationTransitionIfNeeded()
  7. 3.5.x src/Moderation/LingotekContentModerationHandler.php \Drupal\lingotek\Moderation\LingotekContentModerationHandler::performModerationTransitionIfNeeded()
  8. 3.6.x src/Moderation/LingotekContentModerationHandler.php \Drupal\lingotek\Moderation\LingotekContentModerationHandler::performModerationTransitionIfNeeded()
  9. 3.7.x src/Moderation/LingotekContentModerationHandler.php \Drupal\lingotek\Moderation\LingotekContentModerationHandler::performModerationTransitionIfNeeded()
  10. 3.8.x src/Moderation/LingotekContentModerationHandler.php \Drupal\lingotek\Moderation\LingotekContentModerationHandler::performModerationTransitionIfNeeded()

Performs a moderation transition if needed.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The content entity.

Overrides LingotekModerationHandlerInterface::performModerationTransitionIfNeeded

File

src/Moderation/LingotekContentModerationHandler.php, line 97

Class

LingotekContentModerationHandler
Content moderation handler managing the Lingotek integration.

Namespace

Drupal\lingotek\Moderation

Code

public function performModerationTransitionIfNeeded(ContentEntityInterface &$entity) {
  if ($this->moderationInfo
    ->shouldModerateEntitiesOfBundle($entity
    ->getEntityType(), $entity
    ->bundle())) {
    $transition = $this->moderationConfiguration
      ->getDownloadTransition($entity
      ->getEntityTypeId(), $entity
      ->bundle());
    if ($transition) {
      $bundles = $this->entityTypeBundleInfo
        ->getBundleInfo($entity
        ->getEntityTypeId());
      $workflow = NULL;
      if (isset($bundles[$entity
        ->bundle()]['workflow'])) {

        /** @var \Drupal\workflows\WorkflowInterface $workflow */
        $workflow = $this->entityTypeManager
          ->getStorage('workflow')
          ->load($bundles[$entity
          ->bundle()]['workflow']);
        if ($workflow && $workflow
          ->getTypePlugin()
          ->hasTransition($transition)) {
          $theTransition = $workflow
            ->getTypePlugin()
            ->getTransition($transition);
          if ($theTransition !== NULL) {

            // Ensure we can execute this transition.
            $state = $this
              ->getModerationState($entity);
            $validStates = $theTransition
              ->from();
            $validStatesIds = array_keys($validStates);
            if (in_array($state, $validStatesIds)) {
              $this
                ->setModerationState($entity, $theTransition
                ->to()
                ->id());
            }
          }
        }
        else {
          \Drupal::logger('lingotek')
            ->warning('Cannot execute transition for @bundle @entity as the workflow @workflow transition @transition cannot be loaded', [
            '@bundle' => $entity
              ->bundle(),
            '@entity' => (string) $entity
              ->label(),
            '@workflow' => (string) $workflow
              ->label(),
            '@transition' => $transition,
          ]);
        }
      }
    }
  }
}