Possible theme_link and hook_link namespace collision

peterpoe - March 22, 2009 - 16:19
Project:Link
Version:6.x-2.6-beta1
Component:Code
Category:bug report
Priority:normal
Assigned:jcfiala
Status:active
Description

I have a module which implements hook_link as usual like this:

<?php
/**
* Implementation of hook_link
*/
function MYMODULE_link($type, $object, $teaser = FALSE) {
  ...
}
?>

I got a 'missing argument 2' error and missing link form fields on node edit forms, and discovered that my hook_link implementation was invoked instead of the 'theme_link' function of the link module.
I fixed this in in my module this way:

<?php
/**
* Implementation of hook_link
*/
function MYMODULE_link($type, $object = NULL, $teaser = FALSE) {
  if (!
is_array($type)) {
    ...
  }
 
/* link module conflict */
 
else {
    return
theme_link($type);
  }
}
?>

But you should probably change the name of the theme function.

#1

crea - April 25, 2009 - 12:03

Man, you saved me!
I had same problem (CCK Link widged broken in node edit form), and got it fixed with your solution!
#444356: Subtheme of Acquia Marina has broken CCK Link fields

#2

crea - April 25, 2009 - 12:24
Priority:normal» critical

#3

crea - April 25, 2009 - 12:51
Title:theme_link conflicts with hook_link implementation» Possible theme_link and hook_link namespace collision
Priority:critical» normal

After some googling I came to conclusion that giving module and theme same name is indeed bad practice.
However, I can't figure out if its allowed officially.
Drupal Gurus, is it bug or "by design" ?

#4

jcfiala - April 25, 2009 - 13:05

It's something I've run into in the past with nodecarousel, where hook_nodecarousel and theme_nodecarousel could conflict, but then, nodecarousel was the first module I developed.

I agree that it's an unfortunate overlap in this case, and I think it would be nice to change the cck module's theme_link to, perhaps, theme_field_link? But I worry about suddenly breaking people's themes which depend on theme_link. :( I'm up for suggestions on it, though.

#5

jcfiala - April 25, 2009 - 14:10
Version:6.x-2.5» 6.x-2.6-beta1
Assigned to:Anonymous» jcfiala

What I think I can do is introduce theme_field_link (or similar - must check for pre-existing theme_field_link first), and keep the theme_link around to call it for backwards compatibility - that way people can start moving over to the new method without breaking...

But I'm still soliciting opinions/ideas!

#6

jcfiala - April 30, 2009 - 21:18

The basic problem here is that you shouldn't name your theme the same as a module. I will in time introduce theme_field_link as I mention in #5, but this isn't the only namespace collision that can happen.

 
 

Drupal is a registered trademark of Dries Buytaert.