You are here

public static function EntityTypeInfo::bundleFormRedirect in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/src/EntityTypeInfo.php \Drupal\content_moderation\EntityTypeInfo::bundleFormRedirect()
  2. 10 core/modules/content_moderation/src/EntityTypeInfo.php \Drupal\content_moderation\EntityTypeInfo::bundleFormRedirect()

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

core/modules/content_moderation/src/EntityTypeInfo.php, line 397

Class

EntityTypeInfo
Manipulates entity type information.

Namespace

Drupal\content_moderation

Code

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

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  $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(),
    ]);
  }
}