You are here

function _collapse_text_replace_callback in Collapse Text 5

Same name and namespace in other branches
  1. 6 collapse_text.module \_collapse_text_replace_callback()
1 string reference to '_collapse_text_replace_callback'
collapse_text_process in ./collapse_text.module
Provides a layer of encapsulation for the regex call.

File

./collapse_text.module, line 78
collapse_text is an input filter that allows text to be collapsible

Code

function _collapse_text_replace_callback($matches) {

  // 2008-12-15 REMorse (no issue number) added space to make
  // $collapsed work
  $collapsed = $matches[1] == ' collapsed';
  $title = trim($matches[2]);
  $interior = $matches[3];
  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[1]);
  }
  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');
  }
  $render_array = array(
    '#type' => 'fieldset',
    '#title' => $title,
    '#collapsible' => true,
    '#collapsed' => $collapsed,
  );
  $render_array['text_contents'] = array(
    '#type' => 'markup',
    '#value' => '<div>' . $interior . '</div>',
  );
  return drupal_render($render_array);
}