SheppardDigital
SheppardDigital

Reputation: 3255

How do you prevent Drupal 8 from redirecting to the page when a new page has been created?

When you create a new page in Drupal 8 it redirects the user to that page on the site, I would like it to redirect back to the content section of the Admin interface.

Is there a way to do this?

Upvotes: 0

Views: 853

Answers (1)

Ronnie
Ronnie

Reputation: 11198

You need to create a custom module and use

hook_form_alter()

You would start by checking what form it is and then add a custom submit callback like so

function your_module_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  // test you are altering the correct form so wrap the below in an IF
  $form['actions']['submit']['#submit'][] = '_your_module_custom_redirect';
}

function _your_module_custom_redirect($form, FormStateInterface $form_state) {
  $form_state->setRedirect('your route name');
}

or possibly use hook_ENTITY_TYPE_insert() as I think hook_form_alter will run regardless of validation, but I am not 100% on that

Upvotes: 1

Related Questions