From 33366362efbe4f50f654e29d0925024cfc45a76a Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Fri, 27 Jan 2023 13:39:31 +0000
Subject: [PATCH] Issue #3033904 by murilohp, stefan.korn, smustgrave: Hide
 empty description for an administrative block

---
 core/modules/system/system.admin.inc              |  2 +-
 .../modules/menu_test/menu_test.links.menu.yml    |  5 +++++
 .../tests/src/Functional/System/AdminTest.php     | 15 ++++++++++++++-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index 2c166df999e4..ce55fca7bf6b 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -29,7 +29,7 @@ function template_preprocess_admin_block_content(&$variables) {
     $variables['compact'] = system_admin_compact_mode();
     foreach ($variables['content'] as $key => $item) {
       $variables['content'][$key]['link'] = Link::fromTextAndUrl($item['title'], $item['url'])->toString();
-      if (!$variables['compact'] && isset($item['description'])) {
+      if (!$variables['compact'] && !empty($item['description'])) {
         $variables['content'][$key]['description'] = ['#markup' => $item['description']];
       }
       else {
diff --git a/core/modules/system/tests/modules/menu_test/menu_test.links.menu.yml b/core/modules/system/tests/modules/menu_test/menu_test.links.menu.yml
index 2bdb59865a3f..9ba1b8f1bf4f 100644
--- a/core/modules/system/tests/modules/menu_test/menu_test.links.menu.yml
+++ b/core/modules/system/tests/modules/menu_test/menu_test.links.menu.yml
@@ -89,3 +89,8 @@ menu_test.access_check:
   title: 'Test custom route access check'
   route_name: menu_test.router_test_session
   menu_name: account
+
+menu_test.admin_description:
+  title: 'Test custom admin block without description'
+  parent: system.admin_config_content
+  route_name: menu_test.menu_name_test
diff --git a/core/modules/system/tests/src/Functional/System/AdminTest.php b/core/modules/system/tests/src/Functional/System/AdminTest.php
index 261b4b00a2cf..0d4b798cd94d 100644
--- a/core/modules/system/tests/src/Functional/System/AdminTest.php
+++ b/core/modules/system/tests/src/Functional/System/AdminTest.php
@@ -31,7 +31,7 @@ class AdminTest extends BrowserTestBase {
    *
    * @var array
    */
-  protected static $modules = ['locale'];
+  protected static $modules = ['locale', 'menu_test'];
 
   /**
    * {@inheritdoc}
@@ -182,4 +182,17 @@ public function testCompactMode() {
     $this->assertNull($session->getCookie('Drupal.visitor.admin_compact_mode'), 'Compact mode persists off new requests.');
   }
 
+  /**
+   * Tests admin config page blocks without descriptions.
+   */
+  public function testConfigBlocksDescription(): void {
+    // Go to Config administration page.
+    $this->drupalGet('admin/config');
+    $this->assertSession()->statusCodeEquals(200);
+    // Validates the custom block without description.
+    $this->assertSession()->pageTextContains('Test custom admin block without description');
+    // Validates an empty description block.
+    $this->assertSession()->elementNotExists('xpath', '//dd[@class="list-group__description"][not(text())]');
+  }
+
 }
-- 
GitLab