Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. $organisation = entity_ui_form_submit_build_entity('organisation',$organisation, $form, $form_state);
  2. $organisation->save();
  3. drupal_set_message(t('The organisation: @name has been saved.', array('@name' => $organisation->name)));
  4. $form_state['redirect'] = 'admin/organisations';
  5.  
  6. // Return the current form
  7. $function = $form_state['storage']['step'];
  8. $form = $function($form, $form_state, $organisation);
  9. return $form;
  10.  
  11. $organisation = entity_ui_form_submit_build_entity('organisation',$organisation, $form, $form_state);
  12. $organisation->save();
  13.  
  14. function organisation_form($form, &$form_state, $organisation) {
  15. if ($form_state['rebuild']) {
  16. $form_state['input'] = array();
  17. }
  18. if (empty($form_state['storage'])) {
  19. // No step has been set so start with the first.
  20. $form_state['storage'] = array(
  21. 'step' => 'organisation_first_form',
  22. );
  23. }
  24. // Return the current form
  25. $function = $form_state['storage']['step'];
  26. $form = $function($form, $form_state, $organisation);
  27. return $form;
  28. }
  29.  
  30. function organisation_form_submit($form, &$form_state) {
  31. $values = $form_state['values'];
  32. if (isset($values['back']) && $values['op'] == $values['back']) {
  33. // Moving back in form.
  34. $step = $form_state['storage']['step'];
  35. // Call current step submit handler if it exists to unset step form data.
  36. if (function_exists($step . '_submit')) {
  37. $function = $step . '_submit';
  38. $function($form, $form_state);
  39. }
  40. // Remove the last saved step so we use it next.
  41. $last_step = array_pop($form_state['storage']['steps']);
  42. $form_state['storage']['step'] = $last_step;
  43. }
  44. else {
  45. // Record step.
  46. $step = $form_state['storage']['step'];
  47. $form_state['storage']['steps'][] = $step;
  48. // Call step submit handler if it exists.
  49. if (function_exists($step . '_submit')) {
  50. $function = $step . '_submit';
  51. $function($form, $form_state);
  52. }
  53. }
  54. return;
  55. }
  56.  
  57. function organisation_second_form($form, $form_state, $organisation) {
  58. $form['#parents'] = array();
  59. // These variables are needed to build field forms.
  60. $entity_type = 'organisation'; // Substitute with any entity type.
  61. $bundle_name = 'organisation'; // Substitute with the entity's bundle.
  62. $entity = $organisation;
  63. $langcode = LANGUAGE_NONE; // Substitute as appropriate.
  64.  
  65. $field_name = 'hub_position_activities';
  66. $items = field_get_items($entity_type, $entity, $field_name);
  67. $field = field_info_field($field_name);
  68. $instance = field_info_instance($entity_type, $field_name, $bundle_name);
  69. $field_form = field_default_form($entity_type, $entity, $field, $instance, $langcode, $items, $form, $form_state);
  70. $form += $field_form;
  71.  
  72. $field_name = 'hub_market';
  73. $items = field_get_items($entity_type, $entity, $field_name);
  74. $field = field_info_field($field_name);
  75. $instance = field_info_instance($entity_type, $field_name, $bundle_name);
  76. $field_form = field_default_form($entity_type, $entity, $field, $instance, $langcode, $items, $form, $form_state);
  77. $form += $field_form;
  78.  
  79. $form['back'] = array(
  80. '#type' => 'submit',
  81. '#value' => t('Back'),
  82. '#limit_validation_errors' => array(),
  83. '#submit' => array('organisation_second_form_submit'),
  84. '#weight' => 499,
  85. );
  86. $form['submit'] = array(
  87. '#type' => 'submit',
  88. '#value' => t('Next'),
  89. '#weight' => 500,
  90. );
  91. return $form;
  92. }
  93.  
  94. function organisation_second_form_submit($form, &$form_state) {
  95. $values = $form_state['values'];
  96. $form_state['rebuild'] = TRUE;
  97. if (isset($values['back']) && $values['op'] == $values['back']) {
  98. $input = $form_state['input'];
  99. // The user clicked the back button, save values that were input
  100. if (isset($input['hub_position_activities'])) {
  101. $form_state['storage']['hub_position_activities'] = $input['hub_position_activities'];
  102. }
  103. if (isset($input['hub_market'])) {
  104. $form_state['storage']['hub_market'] = $input['hub_market'];
  105. }
  106. $form_state['storage']['step'] = 'organisation_first_form';
  107. }
  108. else {
  109. $form_state['storage']['hub_position_activities'] = $values['hub_position_activities'];
  110. $form_state['storage']['hub_market'] = $values['hub_market'];
  111. $organisation = entity_ui_form_submit_build_entity($form, $form_state);
  112. $organisation->save();
  113. $form_state['storage']['step'] = 'organisation_third_form';
  114. }
  115. }
  116.  
  117. function organisation_last_form_submit($form, &$form_state) {
  118. $values = $form_state['values'];
  119.  
  120.  
  121. if (isset($values['back']) && $values['op'] == $values['back']) {
  122. $form_state['storage']['step'] = 'organisation_second_form';
  123. $form_state['rebuild'] = TRUE;
  124. }
  125. else {
  126. $form_state['storage']['hub_equipment_measurement'] = $values['hub_equipment_measurement'];
  127. $form_state['storage']['hub_equipment_software'] = $values['hub_equipment_software'];
  128. $organisation = entity_ui_form_submit_build_entity($form, $form_state);
  129. $organisation->save();
  130. drupal_set_message(t('The organisation: @name has been saved.', array('@name' => $organisation->name)));
  131. $form_state['redirect'] = 'admin/organisations';
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement