drupal_render
includes/common.inc, строка 2253
- Версии
- 5 – 6
drupal_render(&$elements)
Формирует HTML-код из структурированного массива.
Функция генерирует HTML-код, рекурсивно обходя каждый элемент массива. Обычно функция вызывается другими функциями, например drupal_get_form()
или node_view()
.
Параметры
$elements
Структурированный массив данных для отображения.
Возвращаемое значение
Сформированный HTML-код.
Связанные темы
Код
<?php
function drupal_render(&$elements) {
if (!isset($elements) || (isset($elements['#access']) && !$elements['#access'])) {
return NULL;
}
$content = '';
// Either the elements did not go through form_builder or one of the children
// has a #weight.
if (!isset($elements['#sorted'])) {
uasort($elements, "_element_sort");
}
if (!isset($elements['#children'])) {
$children = element_children($elements);
/* Render all the children that use a theme function */
if (isset($elements['#theme']) && empty($elements['#theme_used'])) {
$elements['#theme_used'] = TRUE;
$previous = array();
foreach (array('#value', '#type', '#prefix', '#suffix') as $key) {
$previous[$key] = isset($elements[$key]) ? $elements[$key] : NULL;
}
// If we rendered a single element, then we will skip the renderer.
if (empty($children)) {
$elements['#printed'] = TRUE;
}
else {
$elements['#value'] = '';
}
$elements['#type'] = 'markup';
unset($elements['#prefix'], $elements['#suffix']);
$content = theme($elements['#theme'], $elements);
foreach (array('#value', '#type', '#prefix', '#suffix') as $key) {
$elements[$key] = isset($previous[$key]) ? $previous[$key] : NULL;
}
}
/* render each of the children using drupal_render and concatenate them */
if (!isset($content) || $content === '') {
foreach ($children as $key) {
$content .= drupal_render($elements[$key]);
}
}
}
if (isset($content) && $content !== '') {
$elements['#children'] = $content;
}
// Until now, we rendered the children, here we render the element itself
if (!isset($elements['#printed'])) {
$content = theme(!empty($elements['#type']) ? $elements['#type'] : 'markup', $elements);
$elements['#printed'] = TRUE;
}
if (isset($content) && $content !== '') {
$prefix = isset($elements['#prefix']) ? $elements['#prefix'] : '';
$suffix = isset($elements['#suffix']) ? $elements['#suffix'] : '';
return $prefix . $content . $suffix;
}
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии