3 namespace Drupal\Core\Render\Element;
5 use Drupal\Core\Form\FormStateInterface;
8 * Stores token data in a hidden form field.
10 * This is generally used to protect against cross-site forgeries. A token
11 * element is automatically added to each Drupal form by an implementation of
12 * \Drupal\Core\Form\FormBuilderInterface::prepareForm() so you don't generally
13 * have to add one yourself.
15 * @FormElement("token")
17 class Token extends Hidden {
22 public function getInfo() {
23 $class = get_class($this);
27 [$class, 'preRenderHidden'],
29 '#theme' => 'input__hidden',
36 public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
37 if ($input !== FALSE && $input !== NULL) {
38 // This should be a string, but allow other scalars since they might be
39 // valid input in programmatic form submissions.
40 return is_scalar($input) ? (string) $input : '';