Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / lib / Drupal / Core / Render / Element / Hidden.php
1 <?php
2
3 namespace Drupal\Core\Render\Element;
4
5 use Drupal\Core\Render\Element;
6
7 /**
8  * Provides a form element for an HTML 'hidden' input element.
9  *
10  * Specify either #default_value or #value but not both.
11  *
12  * Properties:
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.
17  *
18  * Usage example:
19  * @code
20  * $form['entity_id'] = array('#type' => 'hidden', '#value' => $entity_id);
21  * @endcode
22  *
23  * @see \Drupal\Core\Render\Element\Value
24  *
25  * @FormElement("hidden")
26  */
27 class Hidden extends FormElement {
28
29   /**
30    * {@inheritdoc}
31    */
32   public function getInfo() {
33     $class = get_class($this);
34     return [
35       '#input' => TRUE,
36       '#process' => [
37         [$class, 'processAjaxForm'],
38       ],
39       '#pre_render' => [
40         [$class, 'preRenderHidden'],
41       ],
42       '#theme' => 'input__hidden',
43     ];
44   }
45
46   /**
47    * Prepares a #type 'hidden' render element for input.html.twig.
48    *
49    * @param array $element
50    *   An associative array containing the properties of the element.
51    *   Properties used: #name, #value, #attributes.
52    *
53    * @return array
54    *   The $element with prepared variables ready for input.html.twig.
55    */
56   public static function preRenderHidden($element) {
57     $element['#attributes']['type'] = 'hidden';
58     Element::setAttributes($element, ['name', 'value']);
59
60     return $element;
61   }
62
63 }