template.php not overriding theme.inc
tonicbox - May 8, 2009 - 09:57
I've got a template.php with the folowing code to override the _links primary links theme:
<?php
function phptemplate_links($links, $attributes = array('class' => 'links')) {
global $language;
$output = '';
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
$class .= ' active';
}
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
if (isset($link['href'])) {
$link['title'] = check_plain($link['title']) . '<span> </span>';
$link['html'] = TRUE;
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
?>But it doesn't override the theme.inc.
If I change the theme.inc code to the same as above (using 'function theme_links') it works, but obviously I want the theme changes to be done in the template.php, not the theme.inc.
Any ideas?
Lee

Same here, I am also trying
Same here, I am also trying to override theme_links(*) using phptemplate_links(*), but to no avail.
Does anyone know why this is not working?
Same problem here
Also tried with the
function phptemplate_links($links, $attributes = array('class' => 'links')) {global $language;
added in template.php - but no luck. Please help!
Regards,
Mike
-Mike
Try a theme override instead of an engine override?
I'm no expert by any means... but did you try doing a theme override, rather than a template engine override?
That is, in template.php, change:
function phptemplate_links(...to:
function YOURTEMPLATENAME_links(...If that works, maybe there's a bug in the template engine override code in core...?
I've only overridden functions on the theme level, so that's really all the info I can give you.
-Karlheinz
Theme override makes no difference
Hi Karl-Heinz
Thanks for the tip. It didn't make any difference though. My modified links theme only works when it's in the theme.inc file.
The strange thing is that if I call it have the same code in both theme.inc and template.php I get an error saying they can't be the same, so it's obviously reading the template.php file. So why doesn't it override?! Very frustrating!
Any more ideas anyone?
Lee
...
Try clearing the cache in performance settings.
Professional Drupal Design and Theme Services
I've cleared cache but to no
I've cleared cache but to no avail.
Has anyone figured this out yet?
What are you changing?
You know, I'm looking at your code above, and I can't see any difference between it and the theme_links() function in theme.inc. What did you change?
What I'm saying is that perhaps it IS working, but it's not having the effect you want. Maybe you should put a big flashing "HEY PAL IT'S WORKING" sign in the code or something, as a debug.
One other possibility: If your template has both phptemplate_links() AND mytheme_links(), I would imagine that the mytheme_links() function would take precedence. This would also be an issue if e.g. you're writing a sub-theme. (That's why Drupal recommends the mytheme_ method.)
EDIT:
Explain what you mean by this:
-Karlheinz
Did anyone figure this out
Did anyone figure this out yet?
It appears to me that *any* function that resides in *any* .inc file cannot be over-ridden in template.php.
I've tried three times to over-ride such functions, and each time it has failed for no apparent reason.
The only difference between these three and other functions that I have managed to over-ride, is that
these three are in .inc files.
Any ideas or suggestions are welcome.
...
This is not the case dude, think of theme.inc's theme-able functions, which of course we can override in template.php
Professional Drupal Design and Theme Services
That might be the case, but
That might be the case, but from my perspective I've got a 100% failure rate for
functions in .inc files and a 100% success rate over-riding functions elsewhere.
Albeit, I don't know any php, so I'm just copying snippets into template.php
But there does seems to be something going wrong with over-riding .inc files.
...
You need to be more specific; paste an example with details of what you are doing/want to achieve.
Professional Drupal Design and Theme Services
OK, here's one: In
OK, here's one:
In /modules/wysiwyg/editors/timymce.inc there is this function:
function wysiwyg_tinymce_settings($editor, $config, $theme) {
$settings = array(
'gecko_spellcheck' => TRUE,
'button_tile_map' => TRUE, // @todo Add a setting for this.
'document_base_url' => base_path(),
'mode' => 'none',
'plugins' => array(),
'theme' => $theme,
'width' => '100%',
// Strict loading mode must be enabled; otherwise TinyMCE would use
// document.write() in IE and Chrome.
'strict_loading_mode' => TRUE,
// TinyMCE's URL conversion magic breaks Drupal modules that use a special
// syntax for paths. This makes 'relative_urls' obsolete.
'convert_urls' => FALSE,
// The default entity_encoding ('named') converts too many characters in
// languages (like Greek). Since Drupal supports Unicode, we only convert
// HTML control characters and invisible characters. TinyMCE always converts
// XML default characters '&', '<', '>'.
'entities' => '160,nbsp,173,shy,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm',
);
if (isset($config['apply_source_formatting'])) {
$settings['apply_source_formatting'] = $config['apply_source_formatting'];
}
if (isset($config['convert_fonts_to_spans'])) {
$settings['convert_fonts_to_spans'] = $config['convert_fonts_to_spans'];
}
if (isset($config['language'])) {
$settings['language'] = $config['language'];
}
if (isset($config['paste_auto_cleanup_on_paste'])) {
$settings['paste_auto_cleanup_on_paste'] = $config['paste_auto_cleanup_on_paste'];
}
if (isset($config['preformatted'])) {
$settings['preformatted'] = $config['preformatted'];
}
if (isset($config['remove_linebreaks'])) {
$settings['remove_linebreaks'] = $config['remove_linebreaks'];
}
if (isset($config['verify_html'])) {
$settings['verify_html'] = $config['verify_html'];
}
if (!empty($config['css_classes'])) {
$settings['theme_advanced_styles'] = implode(';', array_filter(explode("\n", str_replace("\r", '', $config['css_classes']))));
}
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
$settings['content_css'] = implode(',', wysiwyg_get_css());
}
else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['content_css'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
}
}
You can see I added: 'gecko_spellcheck' => TRUE at the top to turn on firefox spellchecker (which tinymce has off by default). This works BTW.
Aren't I correct in assuming that instead of having to hack the .inc file, I should be able to over-ride the function in template.php and add the spellcheck setting that way?
If not, can you explain why not?
If so, could you give me a clue how I should be doing it?
Thanks for your help.
This is not a theme function,
This is not a theme function, its a module layer function (being called and used in the module layer) the party is over by the time it gets to the theme layer.
The functions you can override in the theme layer all begin with theme_, such as theme_links, theme_item_list and so on.
I dont know anything about this module, I would think what you want sounds like a feature request for the module (perhaps this could be a setting in the module for TinyMCE?) - probably best to address this in the issue queue for the module.
Professional Drupal Design and Theme Services
Theme overrides
To be clear:
Whenever you write a theme override function (let's say "myawesometheme_foo"), Drupal looks for a function called "theme_foo" to override. If there isn't one, it considers it a new function and doesn't override anything.
So, the function you're overriding has to begin with "theme_". If it doesn't, you're out of luck. This is true of both core and contributed modules. You can hack the core (the .inc or .module file associated with the module), but that's not the "Drupal way" of doing things - go to the issue queue and write up a feature request instead.
Here's a list of all the core functions that can be overridden:
http://api.drupal.org/api/group/themeable/6
Also, see the theming handbook page about function overrides:
http://drupal.org/node/173880#function-override
Also, you really should name your function according to theme rather than engine: "mytheme_foo" = good, "phptemplate_foo" = bad. If you do the second, it will override that function for every single theme that uses that template engine, which is probably all of them.
Incidentally, unless you need to change a module's HTML output, you don't need to do a function override, you can just change the CSS.
-Karlheinz
Tidbit
Okay, I was having the same problem, nothing I seemed to try would change "function pixture_reloaded_username($object)" to output what I had changed it too. I even had cache turned off to try and help, well, Drupal's idea of caching being "off" is odd, some other changes in my theme's template.php were showing up, but never the username changes. In desperation, I did it "all"
- Completely closed and cleared the testing browser's cache
- Re-uploaded all changed files
- Manually clear Drupal's cache: Home » Administer » Site configuration » Clear cached data
- Saved theme's configuration: Home » Administer » Site building » Themes » Configure » {the-theme} » "Save Configuration"
And, it worked. "Not verified" finally disappeared like I asked it too.
Computers, such a pain.
Michael
Theme name?
What is your theme name? If it's not "pixture_reloaded," that won't work.
From another of your posts (which I found by searching for "pixture_reloaded_username"), I gathered that the function you're trying to override is theme_username(). If your theme is named "pixture", then the override function should be called "pixture_username()".
If the theme is indeed "pixture_reloaded," then it should work fine. Yes, you will need to clear all caches to see the results, including your browser's cache (usually you can just hit "reload" for this) and Drupal's cached data. If there's some CSS and/or JavaScript involved, it might also help to turn off optimization.
After this, you should visit Admin >Site Building > Themes. Clearing the cached data SHOULD rebuild the theme registry, but visiting this page will do it for sure.
I've also noticed a delay in updating this stuff with some webhosts - I think some might use their own file-caching system.
-Karlheinz