function _collapse_text_replace_callback in Collapse Text 6
Same name and namespace in other branches
- 5 collapse_text.module \_collapse_text_replace_callback()
1 string reference to '_collapse_text_replace_callback'
- collapse_text_process_recurs in ./
collapse_text.module - Provides a layer of encapsulation for the regex call.
File
- ./
collapse_text.module, line 127 - collapse_text is an input filter that allows text to be collapsible
Code
function _collapse_text_replace_callback($matches) {
global $base_url;
// 2008-12-15 REMorse (no issue number) added space to make
// $collapsed work
$collapsed = $matches[1] == ' collapsed';
$style = trim($matches[2]);
$title = trim($matches[3]);
$interior = $matches[4];
if (empty($title)) {
// If a title is not supplied, look for a header (<h1>, <h2> ...)
// and use it as the title.
$h_matches = array();
preg_match('/(<h\\d[^>]*>(.+?)<\\/h\\d>)/smi', $interior, $h_matches);
$title = strip_tags($h_matches[2]);
// If we get the title from the first header tag,
// then we should remove the header tag so it's not repeated
if (!empty($title)) {
$replacement = "";
$occ = 1;
$interior = str_replace($h_matches[0], $replacement, $interior, $occ);
}
}
if (empty($title)) {
// If there is still no title, provide some default text.
// Added call to t() per #256176 yngens
$title = t('Use the arrow to expand or collapse this section');
}
$form = array(
'#prefix' => '<form action="' . $base_url . '/">',
'#suffix' => '</form>',
'#theme' => 'collapse_text_fieldset',
);
$form['fieldset'] = array(
'#type' => 'fieldset',
'#title' => $title,
'#collapsible' => true,
'#collapsed' => $collapsed,
);
if (!empty($style)) {
$form['fieldset']['#attributes'] = array(
'class' => collapse_text_id_safe($style),
);
}
$form['fieldset']['text_contents'] = array(
'#type' => 'markup',
'#prefix' => '<div class="collapse-text">',
'#value' => collapse_text_process_recurs($interior),
'#suffix' => '</div>',
);
return drupal_render($form);
}