function entity2text_renderarray_to_text in Entity To Text 7
1 call to entity2text_renderarray_to_text()
File
- ./
entity2text.module, line 76
Code
function entity2text_renderarray_to_text($render_array, $print_empty_title = FALSE, $indent_text = '') {
$tab_text = " ";
$output = '';
$markup = '';
$title = '';
if (!empty($render_array['#markup'])) {
$markup .= "{$indent_text}{$tab_text}" . htmlspecialchars_decode(strip_tags($render_array['#markup']));
$markup = trim($markup);
}
if (isset($render_array['#title'])) {
$title .= htmlspecialchars_decode(strip_tags($render_array['#title'])) . ":";
$title = trim($title);
}
if (!empty($markup) && empty($title)) {
$output .= "\n" . $indent_text . $markup . "\n";
}
elseif (!empty($markup) && !empty($title)) {
$output .= "\n" . $indent_text . $title . "\n" . $indent_text . $tab_text . $markup;
}
elseif (empty($markup) && !empty($title)) {
$output .= "\n" . $indent_text . $title;
}
if (!empty($output)) {
$indent_text .= $tab_text;
}
foreach (element_children($render_array) as $child) {
// Make any final changes to the element before it is maybe rendered. This
// means that the $element or the children can be altered or corrected
// before the element is rendered into the final text.
if (isset($render_array[$child]['#pre_render'])) {
foreach ($render_array[$child]['#pre_render'] as $function) {
if (function_exists($function)) {
$render_array[$child] = $function($render_array[$child]);
}
}
}
// If there's a type use it to render the element. E.g. address field only
// adds the proper output values in this step.
if (isset($render_array[$child]['#type'])) {
$rendered = drupal_render($render_array[$child]);
// Add line breaks to all block end tags, then strip all tags and
// sanitize.
$child_text = "\n{$indent_text}{$tab_text}" . htmlspecialchars_decode(strip_tags(entity2text_block_hmlt_entities_to_nl($rendered, $indent_text . $tab_text)));
}
else {
$child_text = entity2text_renderarray_to_text($render_array[$child], $print_empty_title, $indent_text);
}
if (isset($render_array[$child]['#weight'])) {
$child_array[$render_array[$child]['#weight']] = $child_text;
}
else {
$child_array[] = $child_text;
}
}
if (!empty($child_array)) {
ksort($child_array);
$output .= implode('', $child_array);
}
return $output;
}