3 namespace Drupal\Core\Render\Element;
5 use Drupal\Core\Render\Element;
8 * Provides a form element for an HTML 'hidden' input element.
10 * Specify either #default_value or #value but not both.
13 * - #default_value: The initial value of the form element. JavaScript may
14 * alter the value prior to submission.
15 * - #value: The value of the form element. The Form API ensures that this
16 * value remains unchanged by the browser.
20 * $form['entity_id'] = array('#type' => 'hidden', '#value' => $entity_id);
23 * @see \Drupal\Core\Render\Element\Value
25 * @FormElement("hidden")
27 class Hidden extends FormElement {
32 public function getInfo() {
33 $class = get_class($this);
37 [$class, 'processAjaxForm'],
40 [$class, 'preRenderHidden'],
42 '#theme' => 'input__hidden',
47 * Prepares a #type 'hidden' render element for input.html.twig.
49 * @param array $element
50 * An associative array containing the properties of the element.
51 * Properties used: #name, #value, #attributes.
54 * The $element with prepared variables ready for input.html.twig.
56 public static function preRenderHidden($element) {
57 $element['#attributes']['type'] = 'hidden';
58 Element::setAttributes($element, ['name', 'value']);