Skip to content
Snippets Groups Projects
Commit e62cc236 authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-5500: adding alternate link to listing pages

parent 20dc2054
No related branches found
No related tags found
1 merge request!70Feature/istwcms 5500 adding rss feeds to listing pages
......@@ -35,10 +35,15 @@ function uw_fdsu_theme_resp_preprocess_html(&$variables) {
$variables['attributes']['class'][] = theme_get_setting('wcms_colour_scheme', 'uw_fdsu_theme_resp') ? theme_get_setting('wcms_colour_scheme', 'uw_fdsu_theme_resp') : 'org-default';
$variables['uw_admin_page'] = \Drupal::service('uw_cfg_common.uw_analytics')->administrationPage();
// Add the fav icons.
_uw_fdsu_theme_resp_add_favicons($variables);
// Get the route name.
$route_name = \Drupal::routeMatch()->getRouteName();
// Perform actions based on the route.
switch ($route_name) {
// Add Javascript only on the user login page.
case 'user.login':
$variables['#attached']['library'][] = 'uw_fdsu_theme_resp/user.login';
......@@ -50,12 +55,51 @@ function uw_fdsu_theme_resp_preprocess_html(&$variables) {
$variables['head_title']['title'] = t('Reference author:') . ' ' . $variables['head_title']['title'];
break;
// Teh header/page title on keywords listing page browser
// The header/page title on keywords listing page browser
// tab shows "Reference keyword: " in front of the keyword.
case 'entity.bibcite_keyword.canonical':
$variables['head_title']['title'] = t('Reference keyword:') . ' ' . $variables['head_title']['title'];
break;
// Adding the alternate link to listing pages.
case 'view.uw_view_blogs.blog_page':
case 'view.uw_view_events.event_page':
case 'view.uw_view_news_items.news_page':
// Get the parameters from the URL.
$parameters = \Drupal::request()->query->all();
// Get the alternate link based on the route.
switch ($route_name) {
case 'view.uw_view_blogs.blog_page':
$link = _uw_fdsu_theme_resp_get_alternate_link(
'uw_view_blogs',
'uw_public_blog_feed',
'Blogs feed'
);
break;
case 'view.uw_view_events.event_page':
$link = _uw_fdsu_theme_resp_get_alternate_link(
'uw_view_events',
'uw_public_event_feed',
'Events feed'
);
break;
case 'view.uw_view_news_items.news_page':
$link = _uw_fdsu_theme_resp_get_alternate_link(
'uw_view_news_items',
'uw_public_news_feed',
'News feed'
);
break;
}
// Add the alternate link to the page.
$variables['#attached']['html_head_link'][] = $link;
break;
}
// Get the current path.
......@@ -72,6 +116,37 @@ function uw_fdsu_theme_resp_preprocess_html(&$variables) {
}
}
/**
* Function to get the alternate link.
*
* @param string $view_machine_name
* The machine name of the view.
* @param string $view_display_name
* The display name of the view.
* @param string $title
* The title of the alternate link.
*/
function _uw_fdsu_theme_resp_get_alternate_link(
string $view_machine_name,
string $view_display_name,
string $title
) {
// Get the URL to RSS feed.
$url = Url::fromRoute('view.' . $view_machine_name . '.' . $view_display_name);
$url->setOptions(['query' => \Drupal::request()->query->all()]);
// Return the link for the alternate.
return [
[
'rel' => 'alternate',
'href' => $url->toString(),
'title' => $title,
'type' => 'application/rss+xml',
]
];
}
/**
* Implements hook_preprocess_responsive_image().
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment