Array Renderer

Array Renderer – Represents the form as an array

Overview

HTML_QuickForm2_Renderer_Array does not generate HTML itself but rather converts the form structure to an array, which can later be used for generating the actual output. It is a port of HTML_QuickForm_Renderer_Array from HTML_QuickForm though generated arrays have some differences due to differences in form structure.

Array Renderer defines a new configuration parameter for setOption() / getOption():

Array Renderer parameters
Parameter name Description Expected type Default value
static_labels Applies only to elements having several labels. If FALSE, label key of the element's array will contain an array of labels as returned by getLabel(). If TRUE element's array will contain several label_* keys corresponding to the keys in label array. boolean FALSE

HTML_QuickForm2_Renderer_Array::toArray() returns the resultant array and HTML_QuickForm2_Renderer_Array::setStyleForId() adds some (opaque) style information to the element's array that can later be used by a template engine.

renderers/array-twig.php example installed with the package shows how to use Array Renderer together with Twig template engine.

Structure of the resultant array


array(
  'id'               => form's "id" attribute (string),
  'frozen'           => whether the form is frozen (bool),
  'attributes'       => attributes for <form> tag (string),
  // if form contains required elements:
  'required_note'    => note about the required elements (string),
  // if 'group_hiddens' option is true:
  'hidden'           => array with html of hidden elements (array),
  // if form has some javascript for setup or validation:
  'javascript'       => form javascript (string)
  // if 'group_errors' option is true:
  'errors' => array(
    '1st element id' => 'Error for the 1st element',
    ...
    'nth element id' => 'Error for the nth element'
  ),
  'elements' => array(
    element_1,
    ...
    element_N
  )
);

where members of the 'elements' array have the following structure


array(
  'id'        => element id (string),
  'type'      => type of the element (string),
  'frozen'    => whether element is frozen (bool),
  // if element has a label:
  'label'     => 'label for the element',
  // note that if 'static_labels' option is true and element's label is an
  // array then there will be several 'label_*' keys corresponding to
  // labels' array keys
  'required'  => whether element is required (bool),
  // if a validation error is present and 'group_errors' option is false:
  'error'     => error associated with the element (string),
  // if some style was associated with an element:
  'style'     => some information about element style (e.g. for Smarty),

  // if element is not a Container
  'value'     => element value (mixed),
  'html'      => HTML for the element (string),

  // if element is a Container
  'attributes' => container attributes (string)
  // only for groups, if separator is set:
  'separator'  => separator for group elements (array),
  'elements'   => array(
    element_1,
    ...
    element_N
  )
);
Directly generates HTML using primitive templates (Previous) Minimum overhead renderer to use when actual form output is done manually (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.