You are here

function _tableofcontents_node_form_alter in Table of Contents 6.3

Same name and namespace in other branches
  1. 7.2 tableofcontents.admin.inc \_tableofcontents_node_form_alter()
  2. 7 tableofcontents.admin.inc \_tableofcontents_node_form_alter()

Add a field so users can ask the TOC to be generated in a node without the use of the filter [toc].

1 call to _tableofcontents_node_form_alter()
tableofcontents_form_alter in ./tableofcontents.module
Add a field in nodes so one can mark the node as using a TOC without the need for the [toc] tag.

File

./tableofcontents.admin.inc, line 439
Include the different setup (administration forms) for the table of contents module.

Code

function _tableofcontents_node_form_alter(&$form) {
  $nid = $form['nid']['#value'];
  if ($nid) {
    $node = node_load($nid);
    $toc_automatic = variable_get('tableofcontents_nodetype_toc_automatic_' . $node->type, 0);
  }
  else {
    $node = (object) array(
      'tableofcontents_toc_automatic' => 0,
    );
    $toc_automatic = variable_get('tableofcontents_nodetype_toc_automatic_' . $form['type']['#value'], 0);
  }
  if ($toc_automatic == 99) {
    $options = array(
      0 => t('No table of contents'),
      1 => t('Add the table at the top'),
      2 => t('Add the table at the bottom'),
    );
    $form['tableofcontents_toc_automatic'] = array(
      '#title' => t('Add a table of content to this node'),
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => $node->tableofcontents_toc_automatic,
      '#description' => t('Select where you want the table of content, or no table.<br/><small>Note that the filter automatic feature takes precedence.</small>'),
    );
  }
}