function FormPreprocess::preprocessForm

Prepares variables for form templates.

Default template: form.html.twig.

Parameters

array $variables: An associative array containing:

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

File

core/lib/Drupal/Core/Form/FormPreprocess.php, line 27

Class

FormPreprocess
Initial preprocess callbacks for the form system.

Namespace

Drupal\Core\Form

Code

public function preprocessForm(array &$variables) : void {
  $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.