Community & Support

Executing custom code after system_settings_form_submit()

Can someone point me to a documentation page which explains the workflow for changing admin settings? Something like http://drupal.org/node/165104 is what I'm after, although I realise that there is no standard route. Specifically I'd like to know what function I can use which gets executed after system_settings_form_submit().

A typical sequence I have seen in several modules is:

  1. admin/settings/mymodule is defined as a 'page callback' calling drupal_get_form with argument 'mymodule_admin'
  2. mymodule_admin() defines the $form, and can optionally register additional functions $form['#submit'][] = 'mymodule_submit'. It returns system_settings_form($form)
  3. mymodule_admin_validate() - this does not need to be registered in the form, it gets executed if it exists.
  4. mymodule_submit() is executed if registered in the form
  5. system_settings_form_submit() in /moduesl/system/system.module - this saves the settings

My problem is that I need to call menu_rebuild() after the settings have been changed, because they affect certain tabs which may be turned
on or off by the admin. Calling menu_rebuild() in steps 3 or 4 above is too early, it needs to be called after step 5 but I do not know
what function or hook I can put it in to get it executed there.

Hope someone can help.

Jonathan

Comments

Don't return system_settings_form, build on it.

<?php
function mymodule_admin() {

 
$form = array();

 
$form['foo'] = array(
    ...
  );

 
$form = system_settings_form($form);

 
$form['#submit'][] = 'custom_callback';

  return
$form;

}
?>

:)

edit: and of course you can skip the custom callback as a wrapper if all you need is menu_rebuild() since it doesn't take any arguments.

<?php
$form
['#submit'][] = 'menu_rebuild';
?>

Brilliant

Thanks very much. I'll give is a try.

Thanks.

Yes, that works exactly how I wanted it.

Thank you very much, Roper.

You're welcome, glad you got

You're welcome, glad you got it going!

nobody click here