Skip to content

Commit

Permalink
chore(SLB-328): redirect to the entity edit form after creating the e…
Browse files Browse the repository at this point in the history
…ntity
  • Loading branch information
chindris committed May 8, 2024
1 parent 920222c commit a1e31e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
36 changes: 36 additions & 0 deletions packages/drupal/entity_create_split/entity_create_split.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* the rest of the fields.
*/

use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\ContentEntityType;
use Drupal\Core\Entity\EntityInterface;

Expand All @@ -29,3 +30,38 @@ function entity_create_split_gutenberg_enabled(EntityInterface $entity) {
return FALSE;
}
}

/**
* Implements hook_form_alter().
*/
function entity_create_split_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$formObject = $form_state->getFormObject();
if ($formObject instanceof ContentEntityForm && $formObject->getFormDisplay($form_state)->getMode() === 'split') {
if (empty($form['#submit'])) {
$form['#submit'] = [];
}
$form['#submit'][] = 'entity_create_split_submit_redirect';
if (!empty($form['actions']['submit']['#submit'])) {
$form['actions']['submit']['#submit'][] = 'entity_create_split_submit_redirect';
}
}
}

/**
* Submit handler for the entity create from, to redirect the user to the entity
* edit form.
*
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*
* @return void
* @throws \Drupal\Core\Entity\EntityMalformedException
*/
function entity_create_split_submit_redirect(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
/* @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $form_state->getFormObject()->getEntity();
if (!empty($entity) && $entity->id()) {
$url = $entity->toUrl('edit-form');
$form_state->setRedirectUrl($url);
}
}
1 change: 0 additions & 1 deletion tests/e2e/specs/drupal/preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ test.describe('instant preview', () => {
.getByLabel('Title', { exact: true })
.fill('Instant preview test');
await page.locator('#edit-submit').click();
await page.locator('li.tabs__tab a:text("Edit")').click();
await page
.locator('#editor-edit-body-0-value h1 span')
.first()
Expand Down

0 comments on commit a1e31e2

Please sign in to comment.