Download & Extend

Possible theme_link and hook_link namespace collision

Project:Link
Version:master
Component:Code
Category:bug report
Priority:major
Assigned:jcfiala
Status:closed (fixed)

Issue Summary

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.

Comments

#1

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

Priority:normal» critical

#3

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

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

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

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.

#7

Priority:normal» critical

*push*

I think this is a critical issue, because it forces people to work around it in other modules, therefore generating more and more locations which could "break". Should be fixed as soon as possible. For now I am using the solution by peterpoe.

#8

Version:6.x-2.6-beta1» master

#9

I'm a little surprised, actually, that this is a problem in drupal 6, because of the need to declare theme functions with hook_theme - if a hook_link implementation is in your code, the theme system shouldn't be finding it and using it if you haven't declared it with hook_theme, I thought. Could folks having this problem chime in on if it's a Drupal 5 or Drupal 6 problem?

I'm not sure if this can be a problem in Drupal 7's fields api, but if it is I'll be definitely switching to theme_field_link. I'm just a little worried about changing the name of a theme function on people.

#10

I am also experiencing this issue with 6.16. I've written a module that implements hook_link() and that hook is called when the Link module calls theme_link() to build the create-content form. I am happy to submit a patch if anyone has an idea other than renaming the theme function. I think renaming is a decision for the maintainers?

#11

Priority:critical» major
Status:active» fixed

#12

Status:fixed» closed (fixed)

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