We use View Reference to provide user modifiable views to various media sites (flicker, youtube, etc.) The client is requesting that I change the text on the Views Reference widget from "Arguments" to more descriptive "Enter Embed Code."
OK - I know how to do this by hacking the View Reference module, but that is bad form and I want to do it the "Drupal Way." But since this text is provided as a process inside of widget it is more difficult than simply overriding the $form array.
From reading (http://drupal.org/node/341628 , http://drupal.org/node/223430), it seems that I
- Need to create a custom theme
- Override the process function within template.php
So far I've been unsuccessful in actually getting it to work though (the site is Drupal 7). The module doesn't seem to provide themeable output for this widget. Can anyone point me to a sample or psudo code on how one would do this in D7?
Thanks in advance,
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | viewsreference.png | 91.99 KB | cluther |
Comments
Comment #1
danielb commentedI've been thinking 'arguments' might be the wrong word to use anyway, I think Views calls it "contextual filter" or something now? I could be wrong.
Since the output is done through the Forms API, it is very easy to change with hook_form_alter().
http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...
or
http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...
The specifics of what the form id is, and where to change the $form would depend on your setup. You can find the form id by implementing hook_form_alter() and making it drupal_set_message($form_id) so you can see what form id's are on the page.
The only catch is if it doesn't work, you might have to attach some sort of callback function through a property like #pre_render to change it later - I know Drupal 6 CCK needed some kind of workaround like that, but you might have to do some research on that.
Theming will not be an appropriate solution.
You can also use the 'string overrides' module to simply to a replace on that word, except it will replace it everywhere it says 'arguments'.
Comment #2
clutherWell actually, not quite. While some of the widget output is modifiable via the $form array, the text that I am looking to change is created by a process unavailable to $form array (see illustration). This was the crux of the question.
So, somewhat answering my own question.....
Hacking the code to change the text would be easy, but bad form as it modifies the Contrib module. So to help those who follow here is my discovery process (information taken from Drupal.org and the Drupal 6 Themes book).
The process which creates the widget text is located at ln 716 in viewreference.module:
The Drupal way would be an override, and various approached to overriding styling are:
Since there is not a themeable function for this widget I'm left to creating a function override in the template.php file. The steps are:
At run time, Drupal is designed to look for overrides to themable functions before applying the default functions. The system does this by looking for files in the following order (assuming the PHPTemplate engine):
But, when I create and modify the function mytheme_select_process($element, &$form_state, $form) nothing happens.
Comment #3
danielb commentedLike I said, theming is not an appropriate solution, and it is not normal to provide a theme hook or template for a widget. I'm not saying it can't work, but your aim is not to change the style of output, rather the data that is fed into the theme functions.
You have to use the forms API like so:
To affect all viewreferences you can loop through $form_state['field'] and find the keys of all the viewreference fields, which can be identified by the 'type' or 'module' keys.
Comment #4
danielb commentedYou know I might just make this configurable.
Comment #5
danielb commenteddone, will appear in next dev version (check the date)
Comment #6
clutherThank you! First for taking the time to further explain your answer (and where I was getting off-track) AND for implementing a solution in the module as a configurable option.