class FormTestController
Same name and namespace in other branches
- 11.x core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php \Drupal\form_test\Controller\FormTestController
Controller routines for form_test routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase extends \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\form_test\Controller\FormTestController implements \Drupal\Core\Controller\ControllerBase
Expanded class hierarchy of FormTestController
File
-
core/
modules/ system/ tests/ modules/ form_test/ src/ Controller/ FormTestController.php, line 13
Namespace
Drupal\form_test\ControllerView source
class FormTestController extends ControllerBase {
/**
* Returns two instances of the node form.
*
* @return string
* A HTML-formatted string with the double node form page content.
*/
public function twoFormInstances() {
$user = $this->currentUser();
$values = [
'uid' => $user->id(),
'name' => $user->getAccountName(),
'type' => 'page',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
];
$node1 = $this->entityTypeManager()
->getStorage('node')
->create($values);
$node2 = clone $node1;
$return['node_form_1'] = $this->entityFormBuilder()
->getForm($node1);
$return['node_form_2'] = $this->entityFormBuilder()
->getForm($node2);
return $return;
}
/**
* Emulate legacy AHAH-style ajax callback.
*
* Drupal 6 AHAH callbacks used to operate directly on forms retrieved using
* \Drupal::formBuilder()->getCache() and stored using
* \Drupal::formBuilder()->setCache() after manipulation. This callback helps
* testing whether \Drupal::formBuilder()->setCache() prevents resaving of
* immutable forms.
*/
public function storageLegacyHandler($form_build_id) {
$form_state = new FormState();
$form = $this->formBuilder()
->getCache($form_build_id, $form_state);
$result = [
'form' => $form,
'form_state' => $form_state,
];
$form['#poisoned'] = TRUE;
$form_state->set('poisoned', TRUE);
$this->formBuilder()
->setCache($form_build_id, $form, $form_state);
return new JsonResponse($result);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.