function EntityTypeInfo::bundleFormRedirect

Same name and namespace in other branches
  1. 9 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()
  3. 11.x 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 384

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(),
        ]);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.