views:

670

answers:

2

I have Drupal 5 View (must be "Views 1" so), which contains Event_StartTime field, which shows up normally for the fields that have a real date inside. But I also have a number of records with Event_StartTime field value like Dec 31 1969 - 8:00pm which looks bad in view and I need to replace them with some custom label, like "No Date Available".

Can I somehow inject this condition (if value = x show value y) into view? Even when I print in "No Date Available" into SQL, the view will show empty field.

To sum up, the general problem is that View fields are kind of limiting, and sometimes you just need to replace some field value, but it's either "date or nothing" or "node-reference id or nothing".

P.S. The situation might be a bit complicated because I use "Bonus: Views Export" module which makes my view return CSV data.

+2  A: 

I'm not really familiar with Views1 anymore, but I think you have at least two options:

  1. At the theming level - you could override the field template and put a check for the particular date value in there, replacing it when found. Of course this check would depend on the formatting of the dates, so if you ever change that, you'd need to adjust the check as well.
  2. At the view generation level - you could execute the view 'manually' from code and inspect the views object right after instantiation and/or after execution, but before rendering (See her for an example of manipulationg the view object in Views2). You could manipulate the result property after execution, but before rendering, or you might be able to put a pre-render callback in there right after instantiation (but I'm not sure if this is already possible in Views1).
Henrik Opel
+2  A: 

Building off of Henrik's comment, theming seems to me to be the best place to do this. You would need to add a function to your template.php file to override that specific view. See the Views 1 theming documentation. Based on this documentation, you create a function with the name of your view of the form

function THEMENAME_view_view_VIEWNAME($view, $type, $nodes, $level = NULL, $args = NULL)

to theme the whole view. $nodes is an array of partially-loaded node objects that are included in your view. You can load each node and check the values of the Event_StartTime field with something like this:

foreach ($nodes as $id => $node) {
  $temp_node = node_load($node->nid);
  //now check value of Event_StartTime assuming that is what you named the field
  if ($temp_node->Event_StartTime === 'Dec 31 1969 - 8:00pm') {
    $temp_node->Event_StartTime = 'No Date Available';
  }
 //output the fields of your view . . .
}

I only showed how to check the value of the Event\_StartTime field, and I am not sure what the actual value is. Dec 31 1969 is before the dates returned by the time() function, so if this does not work you might want to check if Event_StartTime === '', which may be true if the event field is just left empty. You will still have to theme the rest of your fields and output them as HTML, which might be too much of a pain just to change the output of one field. You can also override the output of individual fields. I have not done this so I couldn't walk you through it, but the link I gave above has some documentation on overriding field theming functions.

Jergason