function template_preprocess_form

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

Prepares variables for form templates.

Default template: form.html.twig.

Parameters

$variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #action, #method, #attributes, #children

File

core/includes/form.inc, line 363

Code

function template_preprocess_form(&$variables) {
    $element = $variables['element'];
    if (isset($element['#action'])) {
        $element['#attributes']['action'] = UrlHelper::stripDangerousProtocols($element['#action']);
    }
    Element::setAttributes($element, [
        'method',
        'id',
    ]);
    if (empty($element['#attributes']['accept-charset'])) {
        $element['#attributes']['accept-charset'] = "UTF-8";
    }
    $variables['attributes'] = $element['#attributes'];
    $variables['children'] = $element['#children'];
}

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