function template_preprocess_theming_example_text_form

Implements template_preprocess().

We prepare variables for use inside the theming-example-text-form.tpl.php template file.

In this example, we create a couple new variables, 'text_form' and 'text_form_content', that clean up the form output. Drupal will turn the array keys in the $variables array into variables for use in the template.

So $variables['text_form'] becomes available as $text_form in the template.

See also

theming-example-text-form.tpl.php

Related topics

File

theming_example/theming_example.module, line 360

Code

function template_preprocess_theming_example_text_form(&$variables) {
    $variables['text_form_content'] = array();
    $text_form_hidden = array();
    // Each form element is rendered and saved as a key in $text_form_content, to
    // give the themer the power to print each element independently in the
    // template file.  Hidden form elements have no value in the theme, so they
    // are grouped into a single element.
    foreach (element_children($variables['form']) as $key) {
        $type = $variables['form'][$key]['#type'];
        if ($type == 'hidden' || $type == 'token') {
            $text_form_hidden[] = drupal_render($variables['form'][$key]);
        }
        else {
            $variables['text_form_content'][$key] = drupal_render($variables['form'][$key]);
        }
    }
    $variables['text_form_content']['hidden'] = implode($text_form_hidden);
    // The entire form is then saved in the $text_form variable, to make it easy
    // for the themer to print the whole form.
    $variables['text_form'] = implode($variables['text_form_content']);
}