In my custom module I'm creating a logic with two fields.
The first field is an image and the second is date field. When I choose past date from the date field, the image field should be hidden. If the date value is present or made in future, the image will be visible.
It's working great on hook_node_view, but I can't figure out how to do this on views.
Here's my code:
<?php
function custom_alter_node_view($node, $view_mode, $langcode) {
if ($node->type == 'hot_offers') {
$c = strtotime($node->field_hot_offers_new_date['und'][0]['value']);
$current_time = date("m/d/Y H:i:s");
$d = strtotime($current_time);
if ($c < $d) {
$node->content['field_hot_offers_new_image']['#access'] = FALSE;
}
}
}
I know there's a hook_views_pre_render, but how do I create the same logic, so the image will be visible only if the date field value will be present or in future?
hook_views_pre_render(&$view)
you would look first at$view->name
and then on the correct view, look inside its$view->result
and unset or otherwise modify your image field therein based upon similar logic as above.