diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme index df37797094e3139361fce3de3191dd3de715e9a6..6451a217d369337ffccc816b91240e835da02846 100644 --- a/uw_fdsu_theme_resp.theme +++ b/uw_fdsu_theme_resp.theme @@ -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(). */