Implement hook_content_extra_fields() to allow weighting of results

nicholasThompson - August 17, 2009 - 08:56
Project:Advanced Poll
Version:6.x-1.x-dev
Component:User interface (CSS, Images, etc.)
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Issue tags:CCK
Description

Simply add the following to the end of advpoll.module and the poll results will become a custom weighted field in the field display settings (if CCK is enabled).

<?php
function advpoll_content_extra_fields($type_name) {
 
$extra = array();
 
$types = advpoll_node_info();

  if (
in_array($type_name, array_keys($types))) {
   
$extra['poll'] = array(
     
'label' => t('Poll Results'),
     
'description' => t('Poll Results - this is purely for output weighting'),
     
'weight' => 1,
    );
  }

  return
$extra;
}
?>

Once you have this in there, you can drag the results field to any position. Nothing will appear in the edit form, however if you have any custom fields (such as a node referrer field which lists any other nodes that reference the poll), you have some level of control on which appears first (rather than simply hard coding a weight of 2 to the results).

This is implemented on (and I guess therefore sponsored by?) http://www.sportbusiness.com/ (see http://www.sportbusiness.com/node/170225)

#1

ChrisKennedy - August 19, 2009 - 16:08

Great stuff - thanks Nick :). I'm a bit swamped for the next month and probably can't really review or test any advpoll patches. I've given you commit access because your code is great and I don't want to be the bottleneck - feel free to commit good patches if I don't respond within a few days.

#2

markus_petrux - August 26, 2009 - 11:02
Status:needs review» needs work

Actually, all the top level elements added to the form by advpoll that are not already supported by CCK would have to be added here as well, I think.

hook_content_extra_fields() would have to expose all items added to node view, but also all items added to node edit form. Otherwise, the form elements cannot be positioned correctly in the node edit form, and for example, "Menu settings" appear just below the "Binary question" field. This is worst when there are other elements added by CCK or other modules, even when they are exposed to CCK.

The problem is that CCK takes over the weights of all top level elements in the form, and the resulting value for these weights after the "Manage fields" screen is submitted is unknown. So all elements that are not exposed to CCK may end up at any position in the form.

 
 

Drupal is a registered trademark of Dries Buytaert.