I just recently discovered this module and I just plain love it and am already envisioning use cases for it in my future projects.

Currently I am working on a personal project and I needed a trending functionality and display similar to the one used on CrunchBase.com home page. When I came across the Radioactivity module I knew it fitted the functionality I needed almost exactly except for the field formatter display types.

The radioactivity guage display type was the closest to what i wanted but not quite (see attached image). I searched for a possible API means of extending the module to get what I wanted but failed. So I had no option than to do the dreaded: (:-O)[gasp!] hack the codes as follows:

/**
 * Implements hook_field_formatter_view()
 */
function radioactivity_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
        . . .
        . . .
        . . .
        switch ($settings['type']) {

          case 'none':
            break;

          case 'energy':
            foreach ($items as $delta => $item) {
              $element[$delta] = array(
                '#markup' => $item[RADIOACTIVITY_FIELD_ENERGY],
              );
            }
            break;

          case 'popularity':
            $maximum = ceil(_radioactivity_get_field_maximum($field['id'], $entity_type));
            $maximum = $maximum == 0 ? 1 : $maximum;
            foreach ($items as $delta => $item) {
              $energy          = $item[RADIOACTIVITY_FIELD_ENERGY];
              $element[$delta] = array(
                '#markup' => round(($energy / $maximum) * 100),
              );
            }
            break;

          case 'gauge':
            $maximum = ceil(_radioactivity_get_field_maximum($field['id'], $entity_type));
            $maximum = $maximum == 0 ? 1 : $maximum;
            foreach ($items as $delta => $item) {
              $energy          = $item[RADIOACTIVITY_FIELD_ENERGY];
              $element[$delta] = array(
                '#theme' => 'radioactivity_gauge',
                '#maximum' => $maximum,
                '#energy' => $energy,
              );
            }
            break;

          // A HACK! :-(
          case 'meter':
            $maximum = ceil(_radioactivity_get_field_maximum($field['id'], $entity_type));
            $maximum = $maximum == 0 ? 1 : $maximum;
            $global_max = variable_get('radioactivity_global_maximum', 0);
            foreach ($items as $delta => $item) {
              $energy          = $item[RADIOACTIVITY_FIELD_ENERGY];
              $element[$delta] = array(
                '#theme' => 'radioactivity_meter',
                '#maximum' => $maximum,
                '#global_max' => $global_max,
                '#energy' => $energy,
              );
            }
            break;

As you can see I added a 4th formatter display type: 'meter'. I now created a theme callback for it called: theme_radioactivity_meter, borrowing from the theme_radioactivity_gauge callback. I also made some other changes elsewhere to get what I wanted (see the attached image).

In addition to the display type I was able to add in the above I can also imagine a few other display possibilities I or anyone else can think up hence my suggestion that the formatter functionality be made extensible to be able to accommodate any display type any one can think up for it.

In my opinion this module has a huge potential in this era of 'social trends' and I can envision it in the same utility class level as Rules or Token modules if it could be similarly flexible.

The included raw, percentage and gauge types are too limited. For instance the gauge type is supposed to be the most advanced but allows only 3 color ranges to indicate hotness. What if someone needed more? The only choice here is to do as I did and HACK.

But, I wonder if my suggestions are reasonable enough . Anyone?

CommentFileSizeAuthor
radioactivity-meter-example.png8.71 KBtogbonna
Support from Acquia helps fund testing for Drupal Acquia logo