From 8b92bea8c72d29820452f898749976a4a02474c8 Mon Sep 17 00:00:00 2001 From: Dave Long <dave@longwaveconsulting.com> Date: Fri, 16 Jun 2023 13:54:28 +0100 Subject: [PATCH] Issue #3356515 by fjgarlin, varun verma, smustgrave: Give users a way to access announcements if toolbar module is disabled --- .../announcements_feed.links.menu.yml | 6 ++++++ .../announcements_feed.module | 21 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 core/modules/announcements_feed/announcements_feed.links.menu.yml diff --git a/core/modules/announcements_feed/announcements_feed.links.menu.yml b/core/modules/announcements_feed/announcements_feed.links.menu.yml new file mode 100644 index 000000000000..9b89f138e158 --- /dev/null +++ b/core/modules/announcements_feed/announcements_feed.links.menu.yml @@ -0,0 +1,6 @@ +announcements_feed.announcement: + title: Announcements + description: 'Displays announcements from the Drupal community.' + route_name: announcements_feed.announcement + weight: 10 + parent: system.admin diff --git a/core/modules/announcements_feed/announcements_feed.module b/core/modules/announcements_feed/announcements_feed.module index 6beccb4ef798..2010be0fa45e 100644 --- a/core/modules/announcements_feed/announcements_feed.module +++ b/core/modules/announcements_feed/announcements_feed.module @@ -6,6 +6,7 @@ */ use Drupal\announcements_feed\RenderCallbacks; +use Drupal\Core\Link; use Drupal\Core\Routing\RouteMatchInterface; /** @@ -19,7 +20,9 @@ function announcements_feed_help($route_name, RouteMatchInterface $route_match) $output .= '<p>' . t('The Announcements module displays announcements from the Drupal community. For more information, see the <a href=":documentation">online documentation for the Announcements module</a>.', [':documentation' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/announcements-feed']) . '</p>'; $output .= '<h3>' . t('Uses') . '</h3>'; $output .= '<dl><dt>' . t('Accessing announcements') . '</dt>'; - $output .= '<dd>' . t('Users with the "View drupal.org announcements" permission may click on the "Announcements" item in the administration toolbar to see all announcements relevant to the Drupal version of your site.') . '</dd>'; + $output .= '<dd>' . t('Users with the "View drupal.org announcements" permission may click on the "Announcements" item in the administration toolbar, or access @link, to see all announcements relevant to the Drupal version of your site.', [ + '@link' => Link::createFromRoute(t('Announcements'), 'announcements_feed.announcement')->toString(), + ]) . '</dd>'; $output .= '</dl>'; return $output; } @@ -65,6 +68,22 @@ function announcements_feed_toolbar() { return $items; } +/** + * Implements hook_toolbar_alter(). + */ +function announcements_feed_toolbar_alter(&$items) { + // As the "Announcements" link is shown already in the top toolbar bar, we + // don't need it again in the administration menu tray, so hide it. + if (!empty($items['administration']['tray'])) { + $callable = function (array $element) { + unset($element['administration_menu']['#items']['announcements_feed.announcement']); + return $element; + }; + + $items['administration']['tray']['toolbar_administration']['#pre_render'][] = $callable; + } +} + /** * Implements hook_theme(). */ -- GitLab