From 95dcdb3f58242ba95fd245e9b2edab81036fb02e Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Wed, 19 Jul 2023 15:37:18 +0200
Subject: [PATCH] Issue #3374626 by lauriii, penyaskito, smustgrave, longwave:
 Comment type form title is confusing

---
 core/modules/comment/comment.routing.yml                     | 2 +-
 core/modules/comment/src/CommentTypeForm.php                 | 4 ++++
 .../modules/comment/tests/src/Functional/CommentTypeTest.php | 5 +++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/core/modules/comment/comment.routing.yml b/core/modules/comment/comment.routing.yml
index e92e8daf797c..da7e917880a4 100644
--- a/core/modules/comment/comment.routing.yml
+++ b/core/modules/comment/comment.routing.yml
@@ -135,7 +135,7 @@ entity.comment_type.edit_form:
   path: '/admin/structure/comment/manage/{comment_type}'
   defaults:
     _entity_form: 'comment_type.edit'
-    _title: 'Edit'
+    _title_callback: '\Drupal\Core\Entity\Controller\EntityController::title'
   requirements:
     _entity_access: 'comment_type.update'
   options:
diff --git a/core/modules/comment/src/CommentTypeForm.php b/core/modules/comment/src/CommentTypeForm.php
index 37b1bf973b62..3ab6a6892458 100644
--- a/core/modules/comment/src/CommentTypeForm.php
+++ b/core/modules/comment/src/CommentTypeForm.php
@@ -74,6 +74,10 @@ public function form(array $form, FormStateInterface $form_state) {
 
     $comment_type = $this->entity;
 
+    if ($this->operation === 'edit') {
+      $form['#title'] = $this->t('Edit %label comment type', ['%label' => $comment_type->label()]);
+    }
+
     $form['label'] = [
       '#type' => 'textfield',
       '#title' => $this->t('Label'),
diff --git a/core/modules/comment/tests/src/Functional/CommentTypeTest.php b/core/modules/comment/tests/src/Functional/CommentTypeTest.php
index 1fd9be1fa57d..2e22b9e4ad7d 100644
--- a/core/modules/comment/tests/src/Functional/CommentTypeTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentTypeTest.php
@@ -47,6 +47,7 @@ protected function setUp(): void {
     parent::setUp();
 
     $this->drupalPlaceBlock('page_title_block');
+    $this->drupalPlaceBlock('system_breadcrumb_block');
 
     $this->adminUser = $this->drupalCreateUser($this->permissions);
   }
@@ -67,6 +68,7 @@ public function testCommentTypeCreation() {
     // Ensure that the new comment type admin page can be accessed.
     $this->drupalGet('admin/structure/comment/manage/' . $type->id());
     $this->assertSession()->statusCodeEquals(200);
+    $this->assertSession()->elementTextEquals('css', 'h1', "Edit {$comment_type->label()} comment type");
 
     // Create a comment type via the user interface.
     $edit = [
@@ -81,6 +83,9 @@ public function testCommentTypeCreation() {
     // Asserts that form submit redirects to the expected manage fields page.
     $this->assertSession()->addressEquals('admin/structure/comment/manage/' . $edit['id'] . '/fields');
 
+    // Asserts that the comment type is visible in breadcrumb.
+    $this->assertTrue($this->assertSession()->elementExists('css', 'nav[role="navigation"]')->hasLink('title for foo'));
+
     $comment_type = CommentType::load('foo');
     $this->assertInstanceOf(CommentType::class, $comment_type);
 
-- 
GitLab