multi page install profile woes

Events happening in the community are now at Drupal community events on www.drupal.org.
frob's picture

Hello All,

I have been using install profiles for a while now, but I have never used a multi page, form, wizard style install profile. I was hoping to make something more generic that I use to build sites more quickly. Up till now I have just been reusing the same one over and over and rewriting the parts that do go from site to site.

So to do this I followed the guide in Pro Drupal Development's install profiles chapter and found that it doesn't work. The submit functions are never called. I even downloaded the books source and ran that and it doesn't work either.

Does anyone know of a good online resource for this? I have read through a few install profiles that do it, but it almost seems like magic when the submit functions are called and when they are not. Here is my code perhaps you could just tell me what is wrong.

Remember this is based mostly off of the book.

<?php
/<strong>
*
Perform any final installation tasks for this profile.
*
* @return
*  
An optional HTML string to display to the user on the final installation
*   screen.
*/
function
profile_profile_tasks(&$task, $url) {
if(
$task == 'profile'){
 
// Load install_profile_api() functions.
 
install_include(profile_profile_modules());
 
 
$task = 'site-info';
  return
drupal_get_form('profile_site_info_form',$url);
  }
 
 
/*****     Next Task     *****/
 
if($task == 'site-info') {
   
$task = 'support-message';
   
drupal_set_title(st('Support'));
   
   
$output = '<p>' . st('Some Support Message').'</p>';
   
   
//Build a continue link that goes to the next task
   
$output .= '<p>' . l(st('NEXT!!!'),$url) . '</p>';
   
    return
$output;
  }
 
 
/*****     Next Task     *****/
 
if($task == 'support-message') {

   
// Uninstall the install_profile_api helper module.
   
module_disable(array('install_profile_api'));
   
drupal_set_installed_schema_version('install_profile_api', SCHEMA_UNINSTALLED);
   
$task = 'profile-finished';
  }
}

/</
strong>
*
Define the form used by the site-info task
*
* @
param $form_state
*   Keyed array contains the state of the form.
* @
param $url
*   URL of the current installer path, provided by installer.
*/
function
profile_site_info_form(&$form_state, $url) {
 
$form['site_slogan'] = array(
   
'#type' => 'textfield',
   
'#title' => st('Site Slogan'),
   
'#description' => st('Enter the site slogan.'),
  );
 
$form['nodes'] = array(
   
'#type' => 'textfield',
   
'#title' => st('Number of Static Pages'),
   
'#description' => 'just temporary',
  );
 
$form['submit'] = array(
   
'#type' => 'submit',
   
'#value' => st('Save and continue'),
   
'#weight' => 15,
  );
 
$form['#action'] = $url;
 
$form['#redirect'] = FALSE;
 
 
$hook_form_alter = $_GET['profile'] .'_form_alter';
  if (
function_exists($hook_form_alter)) {
   
$hook_form_alter($form, array(), 'weblishers_site_info');
  }
  return
$form;
}

/**
* Handle form submission for the site info form
*/
function profile_site_info_form_submit($form, &$form_state) {
 
// Set some persistent variables
 
dsm($form);
 
dsm($form_state);
 
variable_set('site_slogan','blah');
 
$theme_settings['toggle_slogan'] = 1;
 
variable_set('site_mission','');
 
variable_set('site_footer','');
 
variable_set('anonymous','Visitor');
}
?>

Comments

Try something like this:   if

ferdi's picture

Try something like this:

  if ($task == 'xx') {
    $output = drupal_get_form('profile_site_info_form', $url);
    if (! variable_get(profile_site_info_form_submitted', FALSE)) {
      return $output;
    }
    else {
      $task = 'some_next_task';
    }
  }

Then in submit do:

function profile_site_info_form_submit($form, &$form_state) {
  // Set some persistent variables
  // etc.

variable_set('profile_site_info_form_submitted', TRUE);
}

That is a great idea. I will

frob's picture

That is a great idea. I will try that.

That worked perfectly. So

frob's picture

That worked perfectly. So exactly is it doing here?

Drupal loads the form the first time, sees that the form has not been submitted and so Drupal renders the form. Then it loads the form the second time, sees that the form has been submitted and so Drupal hands off the submition to the submit function?

Did I get that right? I plan on documenting this so I want to know exactly what is happening.

Distributions

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: