Subtheme search-theme-form.tpl file only called when path from Zen folder is specified

kdebaas - January 27, 2008 - 17:49
Project:Zen
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

When following the README.txt instructions to override the Drupal search form, the search-theme-form.tpl.php file that I placed in the subtheme folder does not get called unless I prepend the path from the Zen directory into the subtheme template.php function:

/**
* Override the Drupal search form using the search-theme-form.tpl.php file.
*/
function phptemplate_search_theme_form($form) {
  return _phptemplate_callback('/SUBTHEME/search-theme-form', array('form' => $form));
}
// */

#1

yched - January 28, 2008 - 18:21

Seeing this too for a few calls to _phptemplate_callback in my subtheme.
And inexplicably, some of them work OK.
It's been driving me nuts since yesterday...

#2

yched - January 28, 2008 - 18:53

Thats' because of these lines in template-subtheme.php - function _zen_hook() :

// Only create a function if $hook contains letters and underscores.
  if (!preg_match('/\W/', $hook)) {

This excludes templates containing a '-'. Is there a real reason for this ?

edit : bleh - of course there is. It's because the code attempts to create a function with '$hook' in it's name...
Anyway - fainally gave me the reason why some of my templates were not called :

_phptemplate_callback($hook, $vars, $suggestion);

$hook cannot contain any '-'. template specialisations ('node-(..)-(..).tpl.php need to be provided through $suggestion

Thus, the sample code provided in the default SUBTHEME phptemplate should be fixed to :

/**
* Override the Drupal search form using the search-theme-form.tpl.php file.
*/
function phptemplate_search_theme_form($form) {
  return _phptemplate_callback('search_theme_form', array('form' => $form));
}

#3

JohnAlbin - January 28, 2008 - 20:57

Yep, you are correct. Hook names have to be valid php function names. BTW, this requirement is caused by Drupal core, not by Zen; take a look at how _phptemplate_callback() works.

Hmm. I got that search box code from the handbooks. Looks like a bug in those docs. http://drupal.org/node/45295 is now fixed.

The function should be:

function phptemplate_search_theme_form($form) {
  return _phptemplate_callback('search_theme_form', array('form' => $form), array('search-theme-form'));
}

#4

JohnAlbin - January 28, 2008 - 21:10
Title:Subtheme search-theme-form.tpl file only called when path from Zen folder is specified» sub-theme's search-theme-form.tpl is ignored

Committed.

#5

JohnAlbin - January 28, 2008 - 21:14
Status:active» fixed

#6

NikLP - January 29, 2008 - 15:19

This thread is somewhat confusing - what is the upshot of this?

Calls to _phptemplate_callback should have the $hook in its Drupal form, ie "user_login_block", with _ as opposed to hyphens? - yes or no?
The template files should still be named with hyphens? yes or no? Or should they now follow with the underscores??

This isn't clear from what's written here.

Edit: not crystal clear, anyway ;)

#7

yched - January 29, 2008 - 15:43

Correct use is
return _phptemplate_callback('search_theme_form', array('form' => $form));
with template search_theme_form.tpl.php

#8

JohnAlbin - January 29, 2008 - 16:16

No, correct use is what I said in #3 above (and what is in 5.x-1.0-beta2). And the file name remains the same: search-theme-form.tpl

What Yves said in #7 will work, too. But Drupal’s naming convention has underscores in hook names and dashes in file names, so the solution in 5.x-1.0-beta2 is more correct.

#9

kdebaas - January 29, 2008 - 17:02
Title:sub-theme's search-theme-form.tpl is ignored» Hook names have to be valid php function names
Status:fixed» active

The most common scenarios for adding code to template.php (in my case) is for theming CCK and Views.

Views Theme Wizard outputs:
$items[] = _phptemplate_callback('views-list-MyView', $vars);
But CCK theming (as from cck/theme/README.txt) behaves:
return _phptemplate_callback('field', $variables, array('field-'. $field['field_name']));

Now I am willing to accept that this is a bug in Views theme export, and I should scurry over there and file an issue. But two questions bother me:

  • Why does this kind of Views Theme Wizard output work in other themes? (a bit of an assumption though)
  • Why does it work when the path to the subtheme tpl.php file is included, like so: _phptemplate_callback('pathtosubtheme/views-list-MyView', $vars); hyphens and all?

#10

JohnAlbin - January 29, 2008 - 21:27
Title:Hook names have to be valid php function names» Subtheme search-theme-form.tpl file only called when path from Zen folder is specified
Status:active» fixed

Why does this kind of Views Theme Wizard output work in other themes?

Because you aren’t creating sub-themes of other themes. The problem occurs because Drupal 5 gives sub-themes a second-class status. There are things you can't do “out of the box” in a normal sub-theme.

There is code in the Zen theme that tries to fix the limitations on sub-themes imposed by D5.

Why does it work when the path to the subtheme tpl.php file is included, like so: _phptemplate_callback('pathtosubtheme/views-list-MyView', $vars); hyphens and all?

Without the subtheme folder prepended to the hook, _phptempalte_callback() first looks for the function called _phptemplate_views-list-MyView(). But since there are dashes in that name, it's not a valid function name. Then it calls _phptemplate_default() which in turn looks for a file called views-list-MyView.tpl.php.

When you add the sub-theme folder, it looks for a function _phptemplate_pathtosubtheme/views-list-MyView() and then for a file called pathtosubtheme/views-list-MyView.tpl.php.

So it is a bug in the Views Theme Wizard. I've submitted a patch: http://drupal.org/node/215570

And, I've re-opened this Zen issue http://drupal.org/node/196181 until the bug gets fixed in Views.

#11

NikLP - January 30, 2008 - 08:12

...aaaand again, what's the "official" workaround for this Views bug, if there is one? Thanks! :)

#12

kdebaas - January 30, 2008 - 08:54

NikLP, that would be to correct
_phptemplate_callback('views-list-VIEWNAME', $vars);
from Views Theme Wizard output into
_phptemplate_callback('views_list_VIEWNAME', $vars, array('views-list-VIEWNAME'));

#13

JohnAlbin - January 30, 2008 - 16:06

Yep, Klass is correct.

#14

NikLP - January 30, 2008 - 19:56

Is that how the callback is rendered in the code exposed by the Views theme wizard then...? So we'd have to hack the output files basically yeah?

I'm just being obtuse on purpose so that anyone reading this thread has a complete plan of what to do :)

#15

Anonymous (not verified) - February 13, 2008 - 20:04
Status:fixed» closed

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

#16

yan - March 24, 2008 - 20:04
Status:closed» active

Hm, I ran into the same problem and tried everything that is suggested here, put still the only ways that work are putting the .tpl.php file to the folder one level above or adding the subtheme folder name (which was the original problem here). Everything else gives me

<!-- PHPTemplate was instructed to override the  views_list_VIEWNAME theme function, but no valid template file was found. -->

#17

marcvangend - April 8, 2008 - 09:27

Yan, in views_list_VIEWNAME, did you replace VIEWNAME with the actual name of your view?

#18

yan - April 9, 2008 - 23:21

Yes I did, marcvangend.

#19

JohnAlbin - April 10, 2008 - 14:19
Status:active» closed

Yan, since you are trying to override a Views Theme Wizard view, this is the correct issue: #196181: Views Theme Wizard: _phptemplate_callback doesn't look in sub-theme folder for .tpl.php files

If you are going to re-open a closed issue, at least open the right one! ;-)

#20

ipwa - April 14, 2008 - 21:04

tracking this issue

#21

JohnAlbin - April 14, 2008 - 21:50

Nicolas, the issue is closed (i.e. FIXED!) And Yan’s issue is a duplicate of a different issue. So there’s nothing to track.

#22

ipwa - April 15, 2008 - 15:55

Sorry JohnAlbin, meant to say "bookmarking" issue, planning on doing some things with search-theme-form.tpl, and wanted to have a way of remembering, sorry for posting on a closed issue.

 
 

Drupal is a registered trademark of Dries Buytaert.