Implements hook_preprocess_HOOK() for page.tpl.php.
function tour_preprocess_page(&$variables) {
if (!user_access('access tour')) {
return;
}
// @todo replace this with http://drupal.org/node/1918768 once it is committed.
$path = current_path();
$tour_items = array();
// Load all of the items and match on path.
$tours = entity_load_multiple('tour');
$path_alias = drupal_strtolower(drupal_container()
->get('path.alias_manager')
->getPathAlias($path));
foreach ($tours as $tour_id => $tour) {
// @todo Replace this with an entity query that does path matching when
// http://drupal.org/node/1918768 lands.
$pages = implode("\n", $tour
->getPaths());
if (!drupal_match_path($path_alias, $pages) && ($path == $path_alias || drupal_match_path($path, $pages))) {
unset($tours[$tour_id]);
}
}
if ($tours) {
$variables['page']['help']['tour'] = entity_view_multiple($tours, 'full');
}
}