You are here

function _tableofcontents_nodetype_form_alter in Table of Contents 7

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

Add a field to the node type so one can define the automatic table of content type on a per type basis.

1 call to _tableofcontents_nodetype_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 498
Include the different setup (administration forms) for the table of contents module.

Code

function _tableofcontents_nodetype_form_alter(&$form) {
  $form['tableofcontents'] = array(
    '#type' => 'fieldset',
    '#title' => t('Table of Contents'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Defines whether a table of content is automatically created on those pages and whether the node_view() function is used along with the filter.'),
    '#group' => 'additional_settings',
  );
  $options = array(
    0 => 'No table of contents',
    1 => 'Add the table at the top',
    2 => 'Add the table at the bottom',
    99 => 'Let user choose on node add/edit',
  );
  $form['tableofcontents']['tableofcontents_toc_automatic'] = array(
    '#type' => 'select',
    '#title' => t('Choose where the automatic table of contents is shown'),
    '#options' => $options,
    '#default_value' => variable_get('tableofcontents_nodetype_toc_automatic_' . $form['#node_type']->type, 0),
    '#description' => t('Select whether the table of content should be shown or not on this type of node.'),
  );
  $form['tableofcontents']['tableofcontents_vtoc'] = array(
    '#title' => t('Transform [vtoc] tags'),
    '#type' => 'checkbox',
    '#default_value' => variable_get('tableofcontents_nodetype_toc_vtoc_' . $form['#node_type']->type, FALSE),
    '#description' => t('Select this option to allow [vtoc] (usually instead of [toc], although if you do not use the filter, both [vtoc] and [toc] will be transformed.) The difference is with the teasers. [vtoc] only works with the Node View hook, not the filters. This means we have the $teaser flag available and know exactly whether the teaser is being generated or not. There are several drawbacks, however: (1) no other filter runs after the table of contents changes, although the data should already be sanetize, there could be a security issue; (2) it does not work with Views and many other modules that will get the body content without running the node_prepare() function; (3) this only works within a node, no other type of data whether it supports a filter or not, will not support a table of content.'),
  );
  $form['tableofcontents']['tableofcontents_remove_from_teaser'] = array(
    '#title' => t('Remove table of contents from the teaser'),
    '#type' => 'checkbox',
    '#default_value' => variable_get('tableofcontents_nodetype_toc_remove_from_teaser_' . $form['#node_type']->type, TRUE),
    '#description' => t('This is the main reason to support [vtoc]: a way to remove the table of contents from your teasers without adding a [toc hide=1;] tag in the teaser. However, as specified in the [vtoc] above, there are drawbacks to this method.'),
  );
  $form['#submit'][] = '_tableofcontents_nodetype_form_alter_submit';
}