You are here

public function Update230::alterTransitions in Lightning Workflow 8.2

Same name and namespace in other branches
  1. 8.3 src/Update/Update230.php \Drupal\lightning_workflow\Update\Update230::alterTransitions()

Alters editorial workflow transitions.

@update

File

src/Update/Update230.php, line 109

Class

Update230
Plugin annotation @Update("2.3.0");

Namespace

Drupal\lightning_workflow\Update

Code

public function alterTransitions(StyleInterface $io) {

  /** @var \Drupal\workflows\WorkflowInterface $workflow */
  $workflow = $this->workflowStorage
    ->load('editorial');
  if (empty($workflow)) {
    return;
  }
  $plugin = $workflow
    ->getTypePlugin();
  $configuration = $plugin
    ->getConfiguration();
  if ($plugin
    ->hasTransitionFromStateToState('draft', 'review')) {
    $transition = $plugin
      ->getTransitionFromStateToState('draft', 'review');
    $question = $this
      ->t('Do you want to rename the "@draft_review" editorial workflow transition to "Send to review"?', [
      '@draft_review' => $transition
        ->label(),
    ]);
    if ($io
      ->confirm($question)) {
      $id = $transition
        ->id();
      $configuration['transitions'][$id]['label'] = 'Send to review';
    }
  }
  if ($plugin
    ->hasTransitionFromStateToState('archived', 'published')) {
    $transition = $plugin
      ->getTransitionFromStateToState('archived', 'published');
    $question = $this
      ->t('Do you want to rename the "@archived_published" editorial workflow transition to "Restore from archive"?', [
      '@archived_published' => $transition
        ->label(),
    ]);
    if ($io
      ->confirm($question)) {
      $id = $transition
        ->id();
      $configuration['transitions'][$id]['label'] = 'Restore from archive';
    }
  }

  // Merge the archived_draft and create_new_draft transitions.
  if ($plugin
    ->hasTransition('archived_draft') && $plugin
    ->hasTransition('create_new_draft')) {
    $transition = $plugin
      ->getTransition('create_new_draft');

    // If the create_new_draft transition can already handle archived items,
    // there's nothing to do. This is an edge case, but worth covering.
    if (array_key_exists('archived', $transition
      ->from())) {
      return;
    }
    $question = $this
      ->t('Do you want to allow the "@create_new_draft" editorial workflow transition to restore archived content into a draft state? This will remove the "@archived_draft" transition.', [
      '@create_new_draft' => $transition
        ->label(),
      '@archived_draft' => $plugin
        ->getTransition('archived_draft')
        ->label(),
    ]);
    if ($io
      ->confirm($question)) {
      unset($configuration['transitions']['archived_draft']);
      $configuration['transitions']['create_new_draft']['from'][] = 'archived';
    }
  }
  $workflow
    ->set('type_settings', $configuration);
  $this->workflowStorage
    ->save($workflow);
}