Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. public function buildForm(array $form, FormStateInterface $form_state) {
  2. ...
  3. if($form_state->getValue('g_actualPartIndex') == NULL){
  4. $form_state->setValue('g_actualPartIndex', 0);
  5. }
  6. $form = $this->setHeader($form, $form_state);
  7.  
  8. $form['Next'] = array(
  9. '#type' => 'submit',
  10. '#value' => "Go to next step",
  11. '#ajax' => [
  12. 'wrapper' => 'projekt-form-wrapper',
  13. 'callback' => [$this, 'form_ajax_submit'],
  14. 'method' => 'replace',
  15. 'effect' => 'fade'
  16. ]
  17. );
  18.  
  19. $form['#prefix'] = '<div id="projekt-form-wrapper">';
  20. $form['#suffix'] = '</div>';
  21. return $form;
  22. }
  23.  
  24. public function form_ajax_submit($form, $form_state) {
  25. $form_state->setValue('g_actualPartIndex',
  26. (int)($form_state->getValue('g_actualPartIndex')) + 1);
  27.  
  28. $form = $this->setHeader($form, $form_state);
  29. $response = new AjaxResponse();
  30. $response->addCommand(new HtmlCommand(
  31. '#projekt-form-wrapper',
  32. $form
  33. ));
  34. return $response;
  35. }
  36.  
  37. private function setHeader(array $form, FormStateInterface $form_state){
  38. $actualPartIndex = $form_state->getValue('g_actualPartIndex');
  39. $form['header'] = array(
  40. '#type' => 'markup',
  41. '#markup' => t('<div id="generatorHeader">
  42. <span class="part '.($actualPartIndex == 0 ? 'active' : '').'">Part 1</span>
  43. <span class="part '.($actualPartIndex == 1 ? 'active' : '').'">Part 2</span>
  44. <span class="part '.($actualPartIndex == 2 ? 'active' : '').'">Part 3</span>
  45. <span class="part '.($actualPartIndex == 3 ? 'active' : '').'">Part 4</span>
  46. <span class="part '.($actualPartIndex == 4 ? 'active' : '').'">Part 5</span>
  47. <span class="part '.($actualPartIndex == 5 ? 'active' : '').'">Part 6</span>
  48. </div>'),
  49. );
  50.  
  51. return $form;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement