At the end of registration_registrations_settings_form_submit, the user is force redirected to viewing the entity for the settings we are saving. With Commerce Registration, this forces the user to the Commerce Product view page, even if the user was previously at a product display node's Manage Registrations tab. This makes it harder for the user to get back to the product display node, as they have to close out of the Commerce Product UI pages and get back to the node they were on.

In my case, I'm using the default Registration settings form builder, validation and submit handlers for settings for Commerce Products, but on a node rather than on the actual Commerce Product admin UI. I'd like to be able to override where the user is redirected to, or do the redirection myself. Both work for me.

Code in question:

$uri = entity_uri($entity['entity_type'],
      entity_load_single($entity['entity_type'], $entity['entity_id']));
drupal_goto($uri['path']);

Could be:

function registration_registrations_settings_form_submit($form, &$form_state, $override_path = NULL) {
...
  $default_uri = entity_uri($entity['entity_type'],
      entity_load_single($entity['entity_type'], $entity['entity_id']));
  $path = ($override_path !== NULL ? $override_path : $default_uri['path']);
  drupal_goto($path);
}

Comments

levelos’s picture

Status: Active » Fixed
jpontani’s picture

Status: Fixed » Active

Is it possible to just move the form_state redirect to the form builder itself? This allows me to override it with a hook_form_alter. As it stands currently, I still can't override it at all as it's being set in the submit handler rather than the form.

levelos’s picture

Status: Active » Closed (works as designed)

You would handle that by adding your own submit handler and setting the redirect destination there.

levelos’s picture

Issue summary: View changes

code fix

  • levelos committed 5008e1a on 7.x-1.x, panels, any-entity, slots, integrations, hold_state
    #1484036: User form_state redirect rather than drupal_goto() when saving...