function google_analytics_reports_views_pre_build in Google Analytics Reports 7.3
Implements hook_views_pre_build().
File
- ./
google_analytics_reports.module, line 304 - Front-end interfaces that use the Google Analytics Reports API module.
Code
function google_analytics_reports_views_pre_build(&$view) {
if ($view->name == 'google_analytics_reports_page' && $view->current_display == 'page') {
// Find page path for Google Analytics.
if (!empty($view->display_handler->options['path'])) {
// Decode current page url, that might appear due to browsers
// particularities.
$current_url = check_plain(urldecode(request_uri()));
// Return front page path ("/") if it is preview in Views UI.
if ($current_url == '/admin/structure/views/view/google_analytics_reports_page/preview/page/ajax') {
$view->args[0] = '/';
return;
}
// Menu path for current view without "%" at the end.
$menu_path = $view->display_handler->options['path'];
$menu_path = str_replace('%', '', $menu_path);
// Real url for Google Analytics.
$ga_url = str_replace($menu_path, '', $current_url);
// Remove old view arguments.
foreach ($view->args as $numb => $value) {
unset($view->args[$numb]);
}
// Set up real Google Analytics path as view argument.
$view->args[0] = $ga_url;
}
}
}