Advertisement
Guest User

Module INC file

a guest
May 12th, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.68 KB | None | 0 0
  1. <?php
  2.  
  3. function sparker_registration_ctools_wizard($step = 'register') {
  4.   // Include required ctools files.
  5.   ctools_include('wizard');
  6.   ctools_include('object-cache');
  7.  
  8.   $form_info = array(
  9.     // Specify unique form id for this form.
  10.     'id' => 'multistep_registration',
  11.     //Specify the path for this form. It is important to include space for the $step argument to be passed.
  12.     'path' => "user/register/%step",
  13.     // Show breadcrumb trail.
  14.     'show trail' => TRUE,
  15.     'show back' => FALSE,
  16.     'show return' => FALSE,
  17.     // Callback to use when the 'next' button is clicked.
  18.     'next callback' => 'sparker_registration_subtask_next',
  19.     // Callback to use when entire form is completed.
  20.     'finish callback' => 'sparker_registration_subtask_finish',
  21.     // Callback to use when user clicks final submit button.
  22.     'return callback' => 'sparker_registration_subtask_finish',
  23.     // Callback to use when user cancels wizard.
  24.     'cancel callback' => 'sparker_registration_subtask_cancel',
  25.     // Specify the order that the child forms will appear in, as well as their page titles.
  26.     'order' => array(
  27.       'register' => t('Register'),
  28.       'groups' => t('Connect'),
  29.       'invite' => t('Invite'),
  30.     ),
  31.     // Define the child forms. Be sure to use the same keys here that were user in the 'order' section of this array.
  32.     'forms' => array(
  33.       'register' => array(
  34.         'form id' => 'user_register_form'
  35.       ),
  36.       'groups' => array(
  37.         'form id' => 'sparker_registration_group_info_form',
  38.         // Be sure to load the required include file if the form callback is not defined in the .module file.
  39.         'include' => drupal_get_path('module', 'sparker_registration') . '/sparker_registration_groups_form.inc',
  40.       ),
  41.       'invite' => array(
  42.         'form id' => 'sparker_registration_invite_form',
  43.       ),
  44.     ),
  45.   );
  46.  
  47.   // Make cached data available within each step's $form_state array.
  48.   $form_state['signup_object'] = sparker_registration_get_page_cache('signup');
  49.  
  50.   // Return the form as a Ctools multi-step form.
  51.   $output = ctools_wizard_multistep_form($form_info, $step, $form_state);
  52.  
  53.   return $output;
  54. }
  55.  
  56. /**
  57.  * Retreives an object from the cache.
  58.  *
  59.  * @param string $name
  60.  *  The name of the cached object to retreive.
  61.  */
  62. function sparker_registration_get_page_cache($name) {
  63.   ctools_include('object-cache');
  64.   $cache = ctools_object_cache_get('sparker_registration', $name);
  65.  
  66.   // If the cached object doesn't exist yet, create an empty object.
  67.   if (!$cache) {
  68.     $cache = new stdClass();
  69.     $cache->locked = ctools_object_cache_test('sparker_registration', $name);
  70.   }
  71.  
  72.   return $cache;
  73. }
  74.  
  75. /**
  76.  * Creates or updates an object in the cache.
  77.  *
  78.  * @param string $name
  79.  *  The name of the object to cache.
  80.  *
  81.  * @param object $data
  82.  *  The object to be cached.
  83.  */
  84. function sparker_registration_set_page_cache($name, $data) {
  85.   ctools_include('object-cache');
  86.   $cache = ctools_object_cache_set('sparker_registration', $name, $data);
  87. }
  88.  
  89. /**
  90.  * Removes an item from the object cache.
  91.  *
  92.  * @param string $name
  93.  *  The name of the object to destroy.
  94.  */
  95. function sparker_registration_clear_page_cache($name) {
  96.   ctools_include('object-cache');
  97.   ctools_object_cache_clear('sparker_registration', $name);
  98. }
  99.  
  100. /**
  101.  * Callback executed when the 'next' button is clicked.
  102.  */
  103. function sparker_registration_subtask_next(&$form_state) {
  104.   // Store submitted data in a ctools cache object, namespaced 'signup'.
  105.   sparker_registration_set_page_cache('signup', $form_state['values']);
  106. }
  107.  
  108. /**
  109.  * Callback executed when the 'cancel' button is clicked.
  110.  */
  111. function sparker_registration_subtask_cancel(&$form_state) {
  112.   // Clear our ctools cache object. It's good housekeeping.
  113.   sparker_registration_clear_page_cache('signup');
  114. }
  115.  
  116. /**
  117.  * Callback executed when the entire form submission is finished.
  118.  */
  119. function sparker_registration_subtask_finish(&$form_state) {
  120.   // Clear our Ctool cache object.
  121.   sparker_registration_clear_page_cache('signup');
  122.  
  123.   // Redirect the user to the front page.
  124.   drupal_goto('<front>');
  125. }
  126.  
  127. function sparker_registration_group_info_form($form, &$form_state) {
  128.   $form['item'] = array(
  129.     '#markup' => t('This is step 2'),
  130.   );
  131.  
  132.   return $form;
  133. }
  134. function sparker_registration_invite_form($form, &$form_state) {
  135.   $form['item'] = array(
  136.     '#markup' => t('This is step 3'),
  137.   );
  138.  
  139.   return $form;
  140. }
  141.  
  142.  
  143.  
  144. /**
  145.  * Implements hook_block_info().
  146.  */
  147. function sparker_registration_block_info() {
  148.   $blocks['register_step1'] = array(
  149.     'info' => t('Grasmash Registration: Step 1'),
  150.     'cache' => DRUPAL_NO_CACHE,
  151.   );
  152.  
  153.   return $blocks;
  154. }
  155.  
  156.  
  157. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement