You are here

function _tableofcontents_node_form_alter in Table of Contents 7.2

Same name and namespace in other branches
  1. 6.3 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 358
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('nodetype_toc_automatic_' . $node->type, 0);
  }
  else {
    $node = (object) array(
      'toc_automatic' => 0,
    );
    $toc_automatic = variable_get('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['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>'),
    );
  }
}