"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/lib/Drupal/Core/Render/Element/Hidden.php" (26 Nov 2020, 1523 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Hidden.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 9.0.8_vs_9.1.0-rc1.

    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 }