I am using a Views field to supply the text for thumbnail hover's breakout fields. The Views field used takes its data from a CCK node reference field. This works ok, but I want to change the text on some breakout fields to use another Views CCK field and add some static text too. I want to use PHP to make the decision. The 2nd field is a CCK Content Taxonomy, Hierarchical Select field - an array with two values, but I'm only interested in one.

I tried using Views Custom field but ran into problems: #997228#comment-5038808 that seem intractable so I abandoned that approach and tried to do it with Computed Field using PHP to make the decision and using Views to get it. I also had problems with this because I need the taxonomy term name, not the term ID, and Computed Field cannot access the full node object - only the term ID is available, not the term name (unless I'm missing something).

So I dug a little deeper using Devel's Theme Developer and decided I needed to override the theme function, "theme_views_slideshow_thumbnailhover_breakout_teaser" in "views_slideshow_thumbnailhover.theme.inc", but can't figure out the API works, and how the module gets it's variables from Views' fields.

I see a node_load performed on line 173 - can I use that to get at the CCK variables I need and bypass using a Views field? How do I modify the function to supply the variable for the new text to be used in the breakout?

Comments

druplicate’s picture

Oops, here's the link to the issue with Views Custom field: #997228: field name in $data gets changed after adding new CCK field comment #7, and #8.

Matt-H’s picture

(This may be all moot at this point, since you found the issue with Views Custom field, but I think it's decent information nonetheless.)

In general, you override a theme function by writing another version of the theme function with your modifications. There are the three levels for theme functions: theme_ , engineName_, and themeName_. When a theme function is called through theme('function'), Drupal looks for themeName_function() and uses it if it finds it, if it doesn't it looks for engineName_function(), and if that doesn't exist, it uses the default implementation, theme_function().

So if you are using a theme called "mytheme", you could write "mytheme_views_slideshow_thumbnailhover_breakout_teaser()", and Drupal will use it when that theme is selected. (The prefix "theme_" gets replaced with the name of the theme, "mytheme_".) Your starting point would be to copy "theme_views_slideshow_thumbnailhover_breakout_teaser()" from views_slideshow_thumbnailhover.theme.inc and put it in template.php, changing the function name.

If you are not using a custom theme but a contributed theme, and you do not want to modify the theme files, then you have the option of using the theme engine name. The default engine name for Drupal 6 is PHPTemplate, so your function would probably be named "phptemplate_views_slideshow_thumbnailhover_breakout_teaser()". This function would override the "theme_ "function. (However, a "mytheme_" function would override that.)

Using a bit more complicated approach, you could override the theme function with a module function. Normally, "mymodule_function" would not be recognized and override the theme function, but it is possible to change the theme registry and tell Drupal what function to use, using hook_theme_registry_alter(). The registry is an array of theme functions and templates, and you can manually add and remove values as needed. So in mymodule, you could write function mymodule_theme_registry_alter(&$theme_registry) and redefine $theme_registry['views_slideshow_thumbnailhover_breakout_teaser']['function'] to be "mymodule_views_slideshow_thumbnailhover_breakout_teaser" The hook_registry_alter would run regardless of which theme is being used, so it would override anything else.

Regarding your other question, I believe that the node_load() will indeed get the cck fields you need, but I don't know where. Since you already are running Devel, I suggest going to /devel/php to execute some php and write something like:

$nid = 123;//The node id of an example node to work with
$node = node_load($nid);
print_r($node);

Then you can see exactly what that node_load gives you. (Although, as the TODO: on that line says, the node_load does load too much. From a performance standpoint, it would be better to loop through the $view->result, collect all the $node->nid values, and write a query to get just the information that is needed - the node titles and whatever else you need.)

druplicate’s picture

I got this to work using Views Custom Field. The original problem was trying to combine one field with PHP and another that was rewritten with custom HTML. You just use the token for the PHP field's result, [phpcode], in the HTML field. As for the PHP variables, just use this form to avoid issues with aliases changing:

<?php
$data->{$this->view->field['field_id']->field_alias}
?>

I never did figure out how to apply that technique to array variables, but if the view never changes you can just use the variable Views gives you which you can find with dpm($data).

redndahead’s picture

Status: Active » Closed (fixed)