class Hidden

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Render/Element/Hidden.php \Drupal\Core\Render\Element\Hidden
  2. 9 core/lib/Drupal/Core/Render/Element/Hidden.php \Drupal\Core\Render\Element\Hidden
  3. 8.9.x core/lib/Drupal/Core/Render/Element/Hidden.php \Drupal\Core\Render\Element\Hidden

Provides a form element for an HTML 'hidden' input element.

Specify either #default_value or #value but not both.

Properties:

  • #default_value: The initial value of the form element. JavaScript may alter the value prior to submission.
  • #value: The value of the form element. The Form API ensures that this value remains unchanged by the browser.

Usage example:

$form['entity_id'] = [
  '#type' => 'hidden',
  '#value' => $entity_id,
];

Attributes

#[FormElement('hidden')]

Hierarchy

Expanded class hierarchy of Hidden

See also

\Drupal\Core\Render\Element\Value

169 string references to 'Hidden'
AjaxTest::testUiAjaxException in core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php
Tests that Ajax errors are visible in the UI.
BaseFieldDefinition::setDisplayConfigurable in core/lib/Drupal/Core/Field/BaseFieldDefinition.php
Sets whether the display for the field can be configured.
block.block.test_block.yml in core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml
core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml
block_content_entity_display.yml in core/modules/block_content/migrations/block_content_entity_display.yml
core/modules/block_content/migrations/block_content_entity_display.yml
ClaroEntityDisplayTest::testEntityForm in core/tests/Drupal/FunctionalJavascriptTests/Theme/ClaroEntityDisplayTest.php
Copied from parent.

... See full list

36 #type uses of Hidden
AddFormBase::buildForm in core/modules/media_library/src/Form/AddFormBase.php
BlockForm::form in core/modules/block/src/BlockForm.php
Gets the actual form array to be built.
BlockListBuilder::buildBlocksForm in core/modules/block/src/BlockListBuilder.php
Builds the main "Blocks" portion of the form.
CKEditor5::buildConfigurationForm in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
ConfirmFormBase::buildForm in core/lib/Drupal/Core/Form/ConfirmFormBase.php

... See full list

File

core/lib/Drupal/Core/Render/Element/Hidden.php, line 26

Namespace

Drupal\Core\Render\Element
View source
class Hidden extends FormElementBase {
  
  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    return [
      '#input' => TRUE,
      '#process' => [
        [
          static::class,
          'processAjaxForm',
        ],
      ],
      '#pre_render' => [
        [
          static::class,
          'preRenderHidden',
        ],
      ],
      '#theme' => 'input__hidden',
    ];
  }
  
  /**
   * Prepares a #type 'hidden' render element for input.html.twig.
   *
   * @param array $element
   *   An associative array containing the properties of the element.
   *   Properties used: #name, #value, #attributes.
   *
   * @return array
   *   The $element with prepared variables ready for input.html.twig.
   */
  public static function preRenderHidden($element) {
    $element['#attributes']['type'] = 'hidden';
    Element::setAttributes($element, [
      'name',
      'value',
    ]);
    return $element;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.