I had occasion to visit function content_types_overview() to see if I could link the type name to one of my modules. I was not really thrilled with having to duplicate this code, especially since it already duplicates core code.

I noticed a "@TODO" that would do what I wanted without having to reproduce the code and _menu_alter.

So here is a patch to introduce hook_content_list(). It is pretty simple; it takes the row before it is added to the table and allows the hook code to alter it. Since the hook could concievably add columns, the "colspan" is increased (as long as it is at least enough, browsers don't care if it is more). Aditionally, the "theme('content_overview_links')" is unnecessary as core already provides an "add" tab.

And here's an example implementation that works great:

 * Implementation of hook_content_list().
 * Requires CCK.
 * @param $row - the array of data passed from CCK's content_types_overview().
 * @param $header - the array of header labels. This must be altered by reference.
 * @return - the modified row.
function get_content_type_content_list($row, &$header) {
  // Can't use the name in $row[0] because it was modified.
  $type = $row[1];
  $row[0] = l(node_get_types('name', $type), "node/type/$type", array('attributes' => array('title' => "Display all $type nodes")));
  return $row;

Actually, life would be a lot easier if the core node module implemented this hook, so CCK could use it rather than duplicating code.

content_list.patch1.21 KBNancyDru


markus_petrux’s picture

Passing &$header for every row seems unnecessary.

How about something that allows altering the whole thing. For example:

+  foreach (module_implements('content_types_overview') as $module) {
+    $function = $module .'_content_types_overview';
+    $function($header, $rows);
+  }

   if (empty($rows)) {
     $rows[] = array(array('data' => t('No content types available.'), 'colspan' => '7', 'class' => 'message'));

   return theme('table', $header, $rows) .theme('content_overview_links');

You can modify the table headers and rows like this:

 * Implementation of hook_content_types_overview().
function MODULE_content_types_overview(&$header, &$rows) {
NancyDru’s picture

That's another possibility. I wish I hadn't stumbled across this when D7 was already in code-slush. It would be so much nicer to have this in core, where it really belongs. Then CCK could be simplified too. But we can start here and move it to core in D8.

markus_petrux’s picture

Status: Needs review » Fixed

I have committed an slight variation of the code in #1 to CCK2 and CCK3.

http://drupal.org/cvs?commit=283096 (CCK2)
http://drupal.org/cvs?commit=283098 (CCK3)

NancyDru’s picture

Fabulous! Thanks. Now, I have to change my module...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.