You are here

function _tableofcontents_get_options in Table of Contents 7

Same name and namespace in other branches
  1. 6.3 tableofcontents.pages.inc \_tableofcontents_get_options()

Parse options and save them in your $toc variable.

@todo This function does NOT check whether you are authorized to parse the options. It parses them. Period.

Parameters

$toc The TOC object where the options are saved:

$options A string of options:

1 call to _tableofcontents_get_options()
_tableofcontents_replace_toc_tags in ./tableofcontents.pages.inc
This function replaces one [toc ...] tag.

File

./tableofcontents.pages.inc, line 400
Applies the filter functions.

Code

function _tableofcontents_get_options(&$toc, $options) {
  static $id_counter = 0;

  // A default identifier for this table of contents
  $toc->id = 'toc';
  if ($id_counter) {
    $toc->id .= $id_counter;
  }
  ++$id_counter;

  // Any options?
  if (!$options) {
    return;
  }

  // Make sure we don't miss the last parameter even if not properly ended
  $options .= ';';

  // We use a replace just so we get the callback
  preg_replace_callback('/([A-Za-z0-9]+)[:=]\\s*([^;]+);/', '_tableofcontents_parse_option', $options);
  if ($toc->minlevel > $toc->maxlevel) {
    drupal_set_message(t("Table of contents error: minlevel (!minlevel) is larger than maxlevel (!maxlevel), reverting to defaults.", array(
      '!minlevel' => $toc->minlevel,
      '!maxlevel' => $toc->maxlevel,
    )), 'error');
    $toc->minlevel = 2;
    $toc->maxlevel = 3;
  }

  // adjust the levels according to the available headers
  if ($toc->minlevel < $toc->header_min) {

    // avoid empty indentations
    $toc->minlevel = $toc->header_min;
    if ($toc->minlevel > $toc->maxlevel) {
      $toc->maxlevel = $toc->minlevel;
    }
  }
  if ($toc->maxlevel > $toc->header_max) {

    // this is much less important
    $toc->maxlevel = $toc->header_max;
  }
}