You are here

function template_preprocess_textarea in Drupal 8

Same name and namespace in other branches
  1. 9 core/includes/form.inc \template_preprocess_textarea()
  2. 10 core/includes/form.inc \template_preprocess_textarea()

Prepares variables for textarea templates.

Default template: textarea.html.twig.

Parameters

array $variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #title, #value, #description, #rows, #cols, #maxlength, #placeholder, #required, #attributes, #resizable.

File

core/includes/form.inc, line 381
Functions for form and batch generation and processing.

Code

function template_preprocess_textarea(&$variables) {
  $element = $variables['element'];
  $attributes = [
    'id',
    'name',
    'rows',
    'cols',
    'maxlength',
    'placeholder',
  ];
  Element::setAttributes($element, $attributes);
  RenderElement::setAttributes($element, [
    'form-textarea',
  ]);
  $variables['wrapper_attributes'] = new Attribute();
  $variables['attributes'] = new Attribute($element['#attributes']);
  $variables['value'] = $element['#value'];
  $variables['resizable'] = !empty($element['#resizable']) ? $element['#resizable'] : NULL;
  $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;
}