diff --git a/src/Form/IndexForm.php b/src/Form/IndexForm.php index a2c71f1..03c2ccd 100644 --- a/src/Form/IndexForm.php +++ b/src/Form/IndexForm.php @@ -547,13 +547,14 @@ class IndexForm extends EntityForm { $actions = parent::actions($form, $form_state); if ($this->getEntity()->isNew()) { - $submit_callbacks = $actions['submit']['#submit']; - $submit_callbacks[] = '::redirectToFieldsForm'; $actions['save_edit'] = array( '#type' => 'submit', '#value' => $this->t('Save and edit'), - '#submit' => $submit_callbacks, + '#submit' => $actions['submit']['#submit'], '#button_type' => 'primary', + // Work around for submit callbacks after save() + // not being called due to batch operations. + '#redirect_to_fields' => TRUE, ); } @@ -608,7 +609,14 @@ class IndexForm extends EntityForm { $index = $this->getEntity(); $index->save(); drupal_set_message($this->t('The index was successfully saved.')); - $form_state->setRedirect('entity.search_api_index.canonical', array('search_api_index' => $index->id())); + + $button = $form_state->getTriggeringElement(); + if(isset($button['#redirect_to_fields'])) { + $form_state->setRedirectUrl($index->toUrl('add-fields')); + } + else { + $form_state->setRedirect('entity.search_api_index.canonical', array('search_api_index' => $index->id())); + } } catch (SearchApiException $ex) { $form_state->setRebuild(); @@ -617,14 +625,4 @@ class IndexForm extends EntityForm { } } } - - /** - * Form submission handler for the 'save and edit' action. - * - * Redirects to the index's "Fields" config form. - */ - public function redirectToFieldsForm(array $form, FormStateInterface $form_state) { - $form_state->setRedirectUrl($this->entity->toUrl('add-fields')); - } - }