Examples:
(my requirement) when wanting to control the content of the view title for a listing of locations (E.g. title "venues near you") created using a view with Drupal module ip_geoloc ("IP Geolocation Views & Maps") based on the user's detected location (via html5 geo location) and then offering further searches (e.g. a different specific location) and wanting to display a different title in those results "venues near New York City"
simpler example "search again" for subsequent displays of the form (an user-visible views exposed filter).
For example 1., I'm currently using hook_views_pre_render
in my own custom module to compare the submitted value with the detected location to be able to set a custom title for the view, snippets (note, not full declaration and module) of how I get each of these here:
$locationAsString = "";
if (function_exists('ip_geoloc_get_visitor_location') ) {
$locationAsArray = ip_geoloc_get_visitor_location();
// debug
//dpm($locationAsArray);
if ( isset($locationAsArray['locality']) ) {
$locationAsString = t($locationAsArray['locality'].", ".$locationAsArray['country']);
}
}
$submittedLocationAsString = "";
if ( isset($view->exposed_raw_input['field_geofield_distance']['origin'] ) )
{
$submittedLocationAsString = $view->exposed_raw_input['field_geofield_distance']['origin'];
}
// debug:
//drupal_set_message( "submitted location is: ".$submittedLocationAsString );
//drupal_set_message( "actuallocation is: ".$locationAsString );
if ( $locationAsString == $submittedLocationAsString )
{
$view->build_info['title'] = "We think you're near ".$locationAsString.". ".$thereAreAsString." here.";
}
else
{
$view->build_info['title'] = $resultsAsString." near ".$submittedLocationAsString;
}
My ideal solution
But as you can see, this straight compare is not necessarily that robust. To determine the title I want, I think it may actually be better to insert a hidden field in the form, in hook_form_alter
and detect the value/presence of this field in cgformutils_views_pre_render
- is this approach within convention and not 'illegal' or bad practice?