Hi,
I'm wondering if nobody else had the same problem: In my installation, the nodetype settings in the administration menu are ignored and every nodetype gets an annotation form field.
Therefore, I changed the code to make it work as it should, added comments and attached the modified module file to this post.
Thanks,
Oli

CommentFileSizeAuthor
#1 annotate.tgz2.15 KBolio
annotate.txt6.62 KBolio

Comments

olio’s picture

Title: all nodetypes get annotation field » all nodetypes get annotation field - *** solved ***
StatusFileSize
new2.15 KB

Answering my own support request: I fixed this issue with three small changes - and a closer look at other modules demonstrating 'best practices' for the same task (in this case, the great 'nodeprofile' module, thanks to it's author!).

To share with the community, I decided to post my solution:

My approach was to not store nodetypes checked as annotation node types (that is, when the annotation checkbox on the content type form was checked and a variable was stored) in an array, but in single variables and to use a small helper function that checks if a nodetype is such an "annotation node type" . Now everything works fine for me and the module does what it should do only for the marked content types.

Here come the modifications, the old code commented out, followed by the replacement code:
1. change: the admin settings form/ annotate_admin_settings()

 * Define the settings form. 
 */ 
function annotate_admin_settings() { 
/* original code: */
/*  $form['annotate_nodetypes'] = array( 
    '#type' => 'checkboxes', 
    '#title' => t('Users may annotate these node types'), 
    '#options' => node_get_types('names'), 
    '#default_value' => variable_get('annotate_nodetype_', array('story')), 
    '#description' => t('A text field will be available on these node types to make user-specific notes.'), 
  );
*/

/**
************ Changed to: ******************
*/
	/* we don't store these nodetypes in an array but in single variables as nodeprofile does. */
  $form['annotate_nodetypes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Users may annotate these node types'),
    '#description' => t('A text field will be available on these node types to make user-specific notes.'), 
  );

  foreach(node_get_types() as $type => $name) {
    $form['annotate_nodetypes']['annotate_nodetype_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => $type,
      '#return_value' => 1,
      '#default_value' => variable_get('annotate_nodetype_' . $type, 0),
    );
  }
	/**
	************ End of change. ******************
	*/	
  
  $form['annotate_deletion'] = array( 
    '#type' => 'radios', 
    '#title' => t('Annotations will be deleted'), 
    '#description' => t('Select a method for deleting annotations.'), 
    '#options' => array( 
      t('Never'), 
      t('Randomly'), 
      t('After 30 days') 
    ), 
    '#default_value' => variable_get('annotate_deletion', 0) // default to Never 
  );
  
  $form['annotate_limit_per_node'] = array( 
    '#type' => 'textfield', 
    '#title' => t('Annotations per node'), 
    '#description' => t('Enter the maximum number of annotations allowed per node (0 for no limit).'), 
    '#default_value' => variable_get('annotate_limit_per_node', 1), 
    '#size' => 3 
  );
  
  // Retrieve stored variables in the settings form.
  $max = variable_get('annotate_limit_per_node', 1);
  $max = variable_get('annotate_deletion', 0);
  
  // Define a validation function. 
  $form['#validate'] = array( 
    'annotate_admin_settings_validate' => array() 
  );
  return system_settings_form($form); 
}

2. change: hook_nodeapi()

/** 
 * Implementation of hook_nodeapi(). 
 */ 
function annotate_nodeapi(&$node, $op, $teaser, $page) { 
  switch ($op) { 
    case 'view': 
      global $user; 
      // If only the node summary is being displayed, or if the 
      // user is an anonymous user (not logged in), abort.
      if ($teaser || $user->uid == 0) { 
        break; 
      } 

			/* original code */
			/*			if (!in_array($node->type, $types_to_annotate)) { 
			        break; 
			      } 

			      // Get previously saved note, if any. 
			      $result = db_query("SELECT note FROM {annotations} WHERE uid = %d AND nid = %d", $user->uid, $node->nid); 
			      $node->annotation = db_result($result); 

			      // Add our form as a content item.
			      $node->content['annotate_form'] = array( 
			        '#value' => drupal_get_form('annotate_entry_form', $node), 
			        '#weight' => 10 
			      );   
			*/
			
			/**
			************ Changed ******************
			*/
      $type_to_annotate = variable_get('annotate_nodetype_' . $type, array('story')); 
			if(!is_annotatetype($node)) { 
					break; 
			} else {
	      // Get previously saved note, if any. 
	      $result = db_query("SELECT note FROM {annotations} WHERE uid = %d AND nid = %d", $user->uid, $node->nid); 
	      $node->annotation = db_result($result); 
      
	      // Add our form as a content item.
	      $node->content['annotate_form'] = array( 
	        '#value' => drupal_get_form('annotate_entry_form', $node), 
	        '#weight' => 10 
	      );
			}   
			/**
			************ End of change ******************
			*/ 
  } 
} 

3. change: a small helper function checking if a specific content type should show an annotation field or not.

/**
************ Addition (this function is copied over from the nodeprofile module.) ******************
*/
/* Check if nodetype is enabled for annotations. */
function is_annotatetype($type) {
  if (is_object($type)) {
    $type = $type->type;
  }
  return variable_get('annotate_nodetype_' . $type, 0);
}
/**
************ End of addition ******************
*/

@Kermitus: Maybe you could have a look at my small solution and decide if it's a possible way to go for the next release ?
And for the other users who can't wait anymore, here's an intermediate solution until the official release is ready (I attached my modified version of the module. I didn't changed anything else in the module, so simply replace the original one with this one and install the update module to get informed as soon as an official release is out.)

clemens.tolboom’s picture

Assigned: Unassigned » clemens.tolboom

Sorry that I first fixed it and then reviewed your solution. Good to change the title too!!!

The is_object( $type) ... is nice to know. It has one drawback in that it creates a lot of variables in the variables table.

Hope my solution in the September 21 release is doing the same functionality.

Regards, Clemens

clemens.tolboom’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)