Formulir API menggunakan # di depan semua properti, untuk membuat perbedaan antara properti, dan elemen anak. Dalam kode berikut, $form['choice_wrapper']['choice']adalah elemen turunan, sementara $form['choice_wrapper']['#tree']adalah properti.
// Add a wrapper for the choices and more button.
$form['choice_wrapper'] = array(
'#tree' => FALSE,
'#weight' => -4,
'#prefix' => '<div class="clearfix" id="poll-choice-wrapper">',
'#suffix' => '</div>',
);
// Container for just the poll choices.
$form['choice_wrapper']['choice'] = array(
'#prefix' => '<div id="poll-choices">',
'#suffix' => '</div>',
'#theme' => 'poll_choices',
);
Semua properti tersebut tercantum dalam referensi API Formulir . Ada banyak properti, tetapi semuanya tentang rendering, validasi, dan pengiriman.
Alasan untuk menggunakan awalan untuk properti adalah untuk dapat dengan cepat menyaring properti dari elemen turunan , yang berguna ketika mereka perlu dirender, misalnya dengan drupal_render () , yang berisi kode berikut.
// Get the children of the element, sorted by weight.
$children = element_children($elements, TRUE);
// Initialize this element's #children, unless a #pre_render callback already
// preset #children.
if (!isset($elements['#children'])) {
$elements['#children'] = '';
}
// Call the element's #theme function if it is set. Then any children of the
// element have to be rendered there.
if (isset($elements['#theme'])) {
$elements['#children'] = theme($elements['#theme'], $elements);
}
// If #theme was not set and the element has children, render them now.
// This is the same process as drupal_render_children() but is inlined
// for speed.
if ($elements['#children'] == '') {
foreach ($children as $key) {
$elements['#children'] .= drupal_render($elements[$key]);
}
}
Jika Anda melihat element_children () , Anda akan melihat kode untuk menyaring properti adalah yang berikut.
// Filter out properties from the element, leaving only children.
$children = array();
$sortable = FALSE;
foreach ($elements as $key => $value) {
if ($key === '' || $key[0] !== '#') {
$children[$key] = $value;
if (is_array($value) && isset($value['#weight'])) {
$sortable = TRUE;
}
}
}