Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $organisation = entity_ui_form_submit_build_entity('organisation',$organisation, $form, $form_state);
- $organisation->save();
- drupal_set_message(t('The organisation: @name has been saved.', array('@name' => $organisation->name)));
- $form_state['redirect'] = 'admin/organisations';
- // Return the current form
- $function = $form_state['storage']['step'];
- $form = $function($form, $form_state, $organisation);
- return $form;
- $organisation = entity_ui_form_submit_build_entity('organisation',$organisation, $form, $form_state);
- $organisation->save();
- function organisation_form($form, &$form_state, $organisation) {
- if ($form_state['rebuild']) {
- $form_state['input'] = array();
- }
- if (empty($form_state['storage'])) {
- // No step has been set so start with the first.
- $form_state['storage'] = array(
- 'step' => 'organisation_first_form',
- );
- }
- // Return the current form
- $function = $form_state['storage']['step'];
- $form = $function($form, $form_state, $organisation);
- return $form;
- }
- function organisation_form_submit($form, &$form_state) {
- $values = $form_state['values'];
- if (isset($values['back']) && $values['op'] == $values['back']) {
- // Moving back in form.
- $step = $form_state['storage']['step'];
- // Call current step submit handler if it exists to unset step form data.
- if (function_exists($step . '_submit')) {
- $function = $step . '_submit';
- $function($form, $form_state);
- }
- // Remove the last saved step so we use it next.
- $last_step = array_pop($form_state['storage']['steps']);
- $form_state['storage']['step'] = $last_step;
- }
- else {
- // Record step.
- $step = $form_state['storage']['step'];
- $form_state['storage']['steps'][] = $step;
- // Call step submit handler if it exists.
- if (function_exists($step . '_submit')) {
- $function = $step . '_submit';
- $function($form, $form_state);
- }
- }
- return;
- }
- function organisation_second_form($form, $form_state, $organisation) {
- $form['#parents'] = array();
- // These variables are needed to build field forms.
- $entity_type = 'organisation'; // Substitute with any entity type.
- $bundle_name = 'organisation'; // Substitute with the entity's bundle.
- $entity = $organisation;
- $langcode = LANGUAGE_NONE; // Substitute as appropriate.
- $field_name = 'hub_position_activities';
- $items = field_get_items($entity_type, $entity, $field_name);
- $field = field_info_field($field_name);
- $instance = field_info_instance($entity_type, $field_name, $bundle_name);
- $field_form = field_default_form($entity_type, $entity, $field, $instance, $langcode, $items, $form, $form_state);
- $form += $field_form;
- $field_name = 'hub_market';
- $items = field_get_items($entity_type, $entity, $field_name);
- $field = field_info_field($field_name);
- $instance = field_info_instance($entity_type, $field_name, $bundle_name);
- $field_form = field_default_form($entity_type, $entity, $field, $instance, $langcode, $items, $form, $form_state);
- $form += $field_form;
- $form['back'] = array(
- '#type' => 'submit',
- '#value' => t('Back'),
- '#limit_validation_errors' => array(),
- '#submit' => array('organisation_second_form_submit'),
- '#weight' => 499,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Next'),
- '#weight' => 500,
- );
- return $form;
- }
- function organisation_second_form_submit($form, &$form_state) {
- $values = $form_state['values'];
- $form_state['rebuild'] = TRUE;
- if (isset($values['back']) && $values['op'] == $values['back']) {
- $input = $form_state['input'];
- // The user clicked the back button, save values that were input
- if (isset($input['hub_position_activities'])) {
- $form_state['storage']['hub_position_activities'] = $input['hub_position_activities'];
- }
- if (isset($input['hub_market'])) {
- $form_state['storage']['hub_market'] = $input['hub_market'];
- }
- $form_state['storage']['step'] = 'organisation_first_form';
- }
- else {
- $form_state['storage']['hub_position_activities'] = $values['hub_position_activities'];
- $form_state['storage']['hub_market'] = $values['hub_market'];
- $organisation = entity_ui_form_submit_build_entity($form, $form_state);
- $organisation->save();
- $form_state['storage']['step'] = 'organisation_third_form';
- }
- }
- function organisation_last_form_submit($form, &$form_state) {
- $values = $form_state['values'];
- if (isset($values['back']) && $values['op'] == $values['back']) {
- $form_state['storage']['step'] = 'organisation_second_form';
- $form_state['rebuild'] = TRUE;
- }
- else {
- $form_state['storage']['hub_equipment_measurement'] = $values['hub_equipment_measurement'];
- $form_state['storage']['hub_equipment_software'] = $values['hub_equipment_software'];
- $organisation = entity_ui_form_submit_build_entity($form, $form_state);
- $organisation->save();
- drupal_set_message(t('The organisation: @name has been saved.', array('@name' => $organisation->name)));
- $form_state['redirect'] = 'admin/organisations';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement