Ok so it seems my callback for my admin settings is not working correctly. It keeps coming back with a HTTP Error 500 (Internal Server Error)

Menu Hook

function annotate_menu(){

 //Makes category
 $items['admin/config/annotate'] = array (
 'title' => 'Node Annotation',
 'description' => 'Adjust node annotation options',
 'position' => 'right',
 'weight' => -5,
 'page callback' => 'system_admin_menu_block_page', //function from system settings.
 'access arguments' => array('administer site configuration'), //who can see this.
 'file' => 'system.admin.inc', //file where callback function is called
 'file path' => drupal_get_path('module', 'system'), //get system module path

 //Makes menu under category
 $items['admin/config/annotate/settings'] = array (
 'title' => 'Annotation Settings',
 'description' => 'Change how annotations behave',
 'page callback' => 'drupal_get_form', //function called
 'page arguments' => array('annotate_admin_settings'), //formID which is function name in annotate.admin.inc
 'access arguments' => array('administer site configuration'), //who can access settings
 'type' => MENU_NORMAL_ITEM,
 'file' => 'annotate.admin.inc', //file where formID is located.

 return $items;

Page Callback

function annotate_admin_settings(){
//get array of node types with "internal names" as keys and "friend names" as values
//$options would return array('page' => 'Basic Page', 'article' => 'Articles');

$types = node_type_get_types(); //module function (node.module) that gets all node types and store in array $types

//go thru the $types array
foreach($types as $node_type){
    $options[$node_type->type] = $node_type->name; //access the $node_type object and store specific properties from the node_type object in $options array

$form['annotate_node_types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Users may annotate these content types'),
    '#options' => $options,
    '#default_value' => variable_get('annotate_node_types', array('page')), //when using the system_settings_form, the name of the form element must match the key of the variable_get ie $form[] = variable_get('$form[]', '')
    '#description' => t('A text field will be available on these content types to make user-specific notes.'),

$form['#submit'][] = 'annotate_admin_settings_submit';
return system_settings_form($form);


process form settings submission

function system_settings_form($form, $form_state){
    //loop thru each of the content type checkboxes shown on the form
    foreach($form_state['values']['annotate_node_types'] as $key => $value){
        //if the check box for a content type is unchecked look to see whether
        //this content type has the annotation field attached to it using the
        //field_info_instance function. if it does then we need to remove the
        //annotation field as the admin has unchecked the box.
            $instance = field_info_instance('node', annotation, $key);
                watchdog("Annotation", 'Deleted annotation field field from content type: %key', array('%key' => $key));
            //if the check box for a content type is checked, look to see whether
            //the field is associated with that content type. if not then add the
            //annotation field to the content type.
            $instance = field_info_instance('node', annotation, $key);
                $instance = array(
                    'field_name' => 'annotation',
                    'entity_type' => 'node',
                    'bundle' => $key,
                    'label' => t('Annotation'),
                    'widget_type' => 'text_textarea_with_summary',
                    'settings' => array('display_summary' => TRUE),
                    'display' => array(
                        'default' => array(
                            'type' => 'text_default',
                        'teaser' => array(
                            'type' => 'text_summary_or_trimmed',
                $instance = field_create_instance($instance);
                watchdog('Annotation', 'Added annotation field to content type: %key', array('%key' => $key));  
    } //end forloop

Change function system_settings_form($form, $form_state) to function annotate_admin_settings_submit($form, $form_state).


system_settings_form() is a function defined from Drupal, and you cannot define the same function twice. The function is defined in system.module, which a module Drupal requires to work.

It is also the wrong name for the form submission handler, as your form builder contains the following line.

$form['#submit'][] = 'annotate_admin_settings_submit';

The form submission handler is then annotate_admin_settings_submit(), not system_settings_form().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.