You are here

public static function ConfigEntityRevisionsEntityTypeInfo::bundleFormRedirect in Config Entity Revisions 8.2

Redirect content entity edit forms on save, if there is a pending revision.

When saving their changes, editors should see those changes displayed on the next page.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

src/ConfigEntityRevisionsEntityTypeInfo.php, line 248

Class

ConfigEntityRevisionsEntityTypeInfo
Class ConfigEntityRevisionsEntityTypeInfo.

Namespace

Drupal\config_entity_revisions

Code

public static function bundleFormRedirect(array &$form, FormStateInterface $form_state) {

  /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  if ($entity instanceof ConfigEntityRevisionsConfigEntityContainerInterface) {
    $entity = $entity
      ->revisionedEntity();
  }
  $moderation_info = \Drupal::getContainer()
    ->get('content_moderation.moderation_information');
  if ($moderation_info
    ->hasPendingRevision($entity) && $entity
    ->hasLinkTemplate('latest-version')) {
    $entity_type_id = $entity
      ->getEntityTypeId();
    $form_state
      ->setRedirect("entity.{$entity_type_id}.latest_version", [
      $entity_type_id => $entity
        ->id(),
    ]);
  }
}