1

Usually I refer to core for best practices. When I was building a system settings form I copied and repurposed the following core implementation.

This define the path for the system setting form that gets invoked via drupal_get_form()

  $items['admin/structure/menu/settings'] = array(
    'title' => 'Settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('menu_configure'),
    'access arguments' => array('administer menu'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 5,
    'file' => 'menu.admin.inc',
    );

And this is the function that build the form:

       /**
        * Menu callback; Build the form presenting menu configuration options.
        */
        function menu_configure() {
          // The form definition is here ..
          //.....

        return system_settings_form($form);
       }

So my question is why isn't the $form param passed to the form function menu_configure()? There are other examples of system settings forms in core, called via the drupal_get_from() that do not have the $form parameter in the parameter list. So is it optional in this case?

2

The form parameter is passed from drupal_get_form(), but if you choose to start a new form array it doesn't really matter. The form works as expected.

However, it's good practice I think to include $form and $form_state in the parameter list because if you ever change your menu entry to pass an argument, then all you need to do in your form builder callback is to add it to the list at the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.