3 namespace Drupal\form_test\Controller;
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\Core\Form\FormState;
7 use Drupal\Core\Language\LanguageInterface;
8 use Symfony\Component\HttpFoundation\JsonResponse;
11 * Controller routines for form_test routes.
13 class FormTestController extends ControllerBase {
16 * Returns two instances of the node form.
19 * A HTML-formatted string with the double node form page content.
21 public function twoFormInstances() {
22 $user = $this->currentUser();
25 'name' => $user->getUsername(),
27 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
29 $node1 = $this->entityManager()->getStorage('node')->create($values);
30 $node2 = clone($node1);
31 $return['node_form_1'] = $this->entityFormBuilder()->getForm($node1);
32 $return['node_form_2'] = $this->entityFormBuilder()->getForm($node2);
37 * Emulate legacy AHAH-style ajax callback.
39 * Drupal 6 AHAH callbacks used to operate directly on forms retrieved using
40 * \Drupal::formBuilder()->getCache() and stored using
41 * \Drupal::formBuilder()->setCache() after manipulation. This callback helps
42 * testing whether \Drupal::formBuilder()->setCache() prevents resaving of
45 public function storageLegacyHandler($form_build_id) {
46 $form_state = new FormState();
47 $form = $this->formBuilder()->getCache($form_build_id, $form_state);
50 'form_state' => $form_state,
52 $form['#poisoned'] = TRUE;
53 $form_state->set('poisoned', TRUE);
54 $this->formBuilder()->setCache($form_build_id, $form, $form_state);
55 return new JsonResponse($result);