diff --git a/templates/views/views-view.html.twig b/templates/views/views-view.html.twig index f11e400f9e667e3313af03df98216e70702538f7..fc126efb6fb250b745df97fdce41f7601697e2c7 100644 --- a/templates/views/views-view.html.twig +++ b/templates/views/views-view.html.twig @@ -81,6 +81,7 @@ 'attachment_after': attachment_after, 'dom_id': dom_id, 'exp_col_all': exp_col_all, + 'rss': view.rss, } %} {% if (view.current_display == 'services_in_category_page') or (view.current_display == 'catalog_a_z_page') %} diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme index df37797094e3139361fce3de3191dd3de715e9a6..7a35f31ee622e28f0c2591ab6c9937026655fd63 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,48 @@ 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 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 +113,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(). */