Same filename and directory in other branches
- 8.9.x core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php
- 9 core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php
Namespace
Drupal\form_test\Form
File
core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php
View source
<?php
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Security\TrustedCallbackInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
class FormTestInputForgeryForm extends FormBase implements TrustedCallbackInterface {
public function getFormId() {
return '_form_test_input_forgery';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['checkboxes'] = [
'#title' => t('Checkboxes'),
'#type' => 'checkboxes',
'#options' => [
'one' => 'One',
'two' => 'Two',
],
];
$form['submit'] = [
'#type' => 'submit',
'#value' => t('Submit'),
];
$form['#post_render'][] = [
static::class,
'postRender',
];
return $form;
}
public static function postRender($rendered_form) {
return str_replace('value="two"', 'value="FORGERY"', $rendered_form);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
return new JsonResponse($form_state
->getValues());
}
public static function trustedCallbacks() {
return [
'postRender',
];
}
}
Classes