From cf7a92f428352df573910f8380679db1749f6a91 Mon Sep 17 00:00:00 2001 From: omkar-pd <omkarpd109@gmail.com> Date: Thu, 13 Feb 2025 10:55:06 +0530 Subject: [PATCH 1/8] #3506267: Changing page title doesn't update in the review changes panel --- src/AutoSave/AutoSaveManager.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AutoSave/AutoSaveManager.php b/src/AutoSave/AutoSaveManager.php index f7f1b961f9..e3c134c3eb 100644 --- a/src/AutoSave/AutoSaveManager.php +++ b/src/AutoSave/AutoSaveManager.php @@ -36,8 +36,7 @@ class AutoSaveManager { 'data' => $data, 'data_hash' => \hash('xxh64', \serialize($data)), 'langcode' => $entity instanceof TranslatableInterface ? $entity->language()->getId() : NULL, - // @todo Update label from incoming entity data once it exists. - 'label' => (string) $entity->label(), + 'label' => (string) $data['entity_form_fields']['title[0][value]'], ]; $this->getTempStore()->set($key, $auto_save_data); $this->cacheTagsInvalidator->invalidateTags([self::CACHE_TAG]); -- GitLab From 9041412dd3edf70bbe7c4473a89ee65adcfe4c64 Mon Sep 17 00:00:00 2001 From: omkar-pd <omkarpd109@gmail.com> Date: Fri, 14 Feb 2025 09:37:06 +0530 Subject: [PATCH 2/8] updated title in AutoSaveManager --- src/AutoSave/AutoSaveManager.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/AutoSave/AutoSaveManager.php b/src/AutoSave/AutoSaveManager.php index e3c134c3eb..513a40ac94 100644 --- a/src/AutoSave/AutoSaveManager.php +++ b/src/AutoSave/AutoSaveManager.php @@ -30,13 +30,16 @@ class AutoSaveManager { public function save(EntityInterface $entity, array $data): void { $key = $this->getAutoSaveKey($entity); + $content_entity_type = $entity->getEntityType(); + $entity_form_fields = $data['entity_form_fields']; + $label_field_input_name = sprintf("%s[0][value]", $content_entity_type->getKey('label')); $auto_save_data = [ 'entity_type' => $entity->getEntityTypeId(), 'entity_id' => $entity->id(), 'data' => $data, 'data_hash' => \hash('xxh64', \serialize($data)), 'langcode' => $entity instanceof TranslatableInterface ? $entity->language()->getId() : NULL, - 'label' => (string) $data['entity_form_fields']['title[0][value]'], + 'label' => (string) $entity_form_fields[$label_field_input_name], ]; $this->getTempStore()->set($key, $auto_save_data); $this->cacheTagsInvalidator->invalidateTags([self::CACHE_TAG]); -- GitLab From 73a485b95cb967ff8126d87cd120cda4c46cc9b6 Mon Sep 17 00:00:00 2001 From: AKHIL BABU <akhilbabui1998@gmail.com> Date: Fri, 14 Feb 2025 16:02:57 +0530 Subject: [PATCH 3/8] Issues/3506267: Add tests. --- src/AutoSave/AutoSaveManager.php | 11 +++++++---- tests/src/Kernel/ApiPendingChangesControllerTest.php | 7 +++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/AutoSave/AutoSaveManager.php b/src/AutoSave/AutoSaveManager.php index 513a40ac94..4163bc3f89 100644 --- a/src/AutoSave/AutoSaveManager.php +++ b/src/AutoSave/AutoSaveManager.php @@ -30,21 +30,24 @@ class AutoSaveManager { public function save(EntityInterface $entity, array $data): void { $key = $this->getAutoSaveKey($entity); - $content_entity_type = $entity->getEntityType(); - $entity_form_fields = $data['entity_form_fields']; - $label_field_input_name = sprintf("%s[0][value]", $content_entity_type->getKey('label')); $auto_save_data = [ 'entity_type' => $entity->getEntityTypeId(), 'entity_id' => $entity->id(), 'data' => $data, 'data_hash' => \hash('xxh64', \serialize($data)), 'langcode' => $entity instanceof TranslatableInterface ? $entity->language()->getId() : NULL, - 'label' => (string) $entity_form_fields[$label_field_input_name], + 'label' => self::getLabelToSave($entity, $data), ]; $this->getTempStore()->set($key, $auto_save_data); $this->cacheTagsInvalidator->invalidateTags([self::CACHE_TAG]); } + public static function getLabelToSave(EntityInterface $entity, array $data): string { + return empty($data['entity_form_fields']) + ? (string) $entity->label() + : (string) $data['entity_form_fields'][sprintf("%s[0][value]", $entity->getEntityType()->getKey('label'))]; + } + public static function getAutoSaveKey(EntityInterface $entity): string { // @todo Make use of https://www.drupal.org/project/drupal/issues/3026957 // @todo This will likely to also take into account the workspace ID. diff --git a/tests/src/Kernel/ApiPendingChangesControllerTest.php b/tests/src/Kernel/ApiPendingChangesControllerTest.php index 3b01cbbb95..314be9cdeb 100644 --- a/tests/src/Kernel/ApiPendingChangesControllerTest.php +++ b/tests/src/Kernel/ApiPendingChangesControllerTest.php @@ -98,7 +98,10 @@ final class ApiPendingChangesControllerTest extends KernelTestBase { self::assertNotFalse($sampleData); $data = \json_decode($sampleData, TRUE); $data += ['entity_form_fields' => []]; - // Full data. + // Update the page title. + $new_title = $this->getRandomGenerator()->sentences(10); + $data['entity_form_fields']['title[0][value]'] = $new_title; + $account1content = Node::load(1); \assert($account1content instanceof NodeInterface); $autoSave->save($account1content, $data); @@ -231,7 +234,7 @@ final class ApiPendingChangesControllerTest extends KernelTestBase { 'avatar' => $avatarUrl, 'uri' => $account1->toUrl()->toString(), ], - 'label' => $account1content->label(), + 'label' => $new_title, 'data_hash' => \hash('xxh64', \serialize($data)), ], \array_diff_key($content['node:1:en'], \array_flip(['updated']))); self::assertEquals([ -- GitLab From c6852b32412ccc102658872746b0c5766772251c Mon Sep 17 00:00:00 2001 From: AKHIL BABU <akhilbabui1998@gmail.com> Date: Fri, 14 Feb 2025 18:03:49 +0530 Subject: [PATCH 4/8] Issues/3506267: Add tests. --- tests/src/Kernel/ApiPublishAllControllerTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/src/Kernel/ApiPublishAllControllerTest.php b/tests/src/Kernel/ApiPublishAllControllerTest.php index 486ec3f389..d5a5424067 100644 --- a/tests/src/Kernel/ApiPublishAllControllerTest.php +++ b/tests/src/Kernel/ApiPublishAllControllerTest.php @@ -328,7 +328,7 @@ class ApiPublishAllControllerTest extends KernelTestBase { 'meta' => [ 'entity_type' => 'node', 'entity_id' => $node1->id(), - 'label' => $node1->label(), + 'label' => $validClientJson['entity_form_fields']['title[0][value]'], 'autosave_key' => $autoSave->getAutoSaveKey($node1), ], ], @@ -371,6 +371,13 @@ class ApiPublishAllControllerTest extends KernelTestBase { 'autosave_key' => $autoSave->getAutoSaveKey($node1), ], ], + 'code' => ErrorCodesEnum::UnmatchedItemInPublishRequest->value, + 'meta' => [ + 'entity_type' => 'node', + 'entity_id' => $node1->id(), + 'label' => $validClientJson['entity_form_fields']['title[0][value]'], + 'autosave_key' => $autoSave->getAutoSaveKey($node1), + ], ], ], \json_decode($response->getContent() ?: '', TRUE, flags: JSON_THROW_ON_ERROR)); -- GitLab From 61991cfb3a6121b863dec845bda7a1a3e8f7b227 Mon Sep 17 00:00:00 2001 From: AKHIL BABU <akhilbabui1998@gmail.com> Date: Fri, 14 Feb 2025 18:13:57 +0530 Subject: [PATCH 5/8] Issues/3506267: Add tests. --- tests/src/Kernel/ApiPublishAllControllerTest.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/src/Kernel/ApiPublishAllControllerTest.php b/tests/src/Kernel/ApiPublishAllControllerTest.php index d5a5424067..8ba59af0f9 100644 --- a/tests/src/Kernel/ApiPublishAllControllerTest.php +++ b/tests/src/Kernel/ApiPublishAllControllerTest.php @@ -367,17 +367,10 @@ class ApiPublishAllControllerTest extends KernelTestBase { 'meta' => [ 'entity_type' => 'node', 'entity_id' => $node1->id(), - 'label' => $node1->label(), + 'label' => $validClientJson['entity_form_fields']['title[0][value]'], 'autosave_key' => $autoSave->getAutoSaveKey($node1), ], ], - 'code' => ErrorCodesEnum::UnmatchedItemInPublishRequest->value, - 'meta' => [ - 'entity_type' => 'node', - 'entity_id' => $node1->id(), - 'label' => $validClientJson['entity_form_fields']['title[0][value]'], - 'autosave_key' => $autoSave->getAutoSaveKey($node1), - ], ], ], \json_decode($response->getContent() ?: '', TRUE, flags: JSON_THROW_ON_ERROR)); -- GitLab From 885255bb109a5529679071a1e22e2f1e3e557e3c Mon Sep 17 00:00:00 2001 From: Ted Bowman <41201-tedbow@users.noreply.drupalcode.org> Date: Tue, 18 Feb 2025 17:06:23 +0000 Subject: [PATCH 6/8] Handle empty title in form field Co-authored by: @larowlan --- src/AutoSave/AutoSaveManager.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/AutoSave/AutoSaveManager.php b/src/AutoSave/AutoSaveManager.php index a01656cd51..cf3f111169 100644 --- a/src/AutoSave/AutoSaveManager.php +++ b/src/AutoSave/AutoSaveManager.php @@ -43,9 +43,8 @@ class AutoSaveManager { } public static function getLabelToSave(EntityInterface $entity, array $data): string { - return empty($data['entity_form_fields']) - ? (string) $entity->label() - : (string) $data['entity_form_fields'][sprintf("%s[0][value]", $entity->getEntityType()->getKey('label'))]; + $key = \sprintf("%s[0][value]", $entity->getEntityType()->getKey('label')); + return $data['entity_form_fields'][$key] ?? (string) $entity->label(); } public static function getAutoSaveKey(EntityInterface $entity): string { -- GitLab From b9c7470cb35a80812a96de6fd27bceb17a27e40f Mon Sep 17 00:00:00 2001 From: Ted Bowman <ted+git@tedbow.com> Date: Tue, 18 Feb 2025 12:25:58 -0500 Subject: [PATCH 7/8] fallback to saved title when form field is empty --- src/AutoSave/AutoSaveManager.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AutoSave/AutoSaveManager.php b/src/AutoSave/AutoSaveManager.php index cf3f111169..bc38385bb9 100644 --- a/src/AutoSave/AutoSaveManager.php +++ b/src/AutoSave/AutoSaveManager.php @@ -44,7 +44,9 @@ class AutoSaveManager { public static function getLabelToSave(EntityInterface $entity, array $data): string { $key = \sprintf("%s[0][value]", $entity->getEntityType()->getKey('label')); - return $data['entity_form_fields'][$key] ?? (string) $entity->label(); + return empty($data['entity_form_fields'][$key]) ? + (string) $entity->label() : + (string) $data['entity_form_fields'][$key]; } public static function getAutoSaveKey(EntityInterface $entity): string { -- GitLab From 92918370b747cc42b1ddd13bc3409c91c7af136c Mon Sep 17 00:00:00 2001 From: Ted Bowman <ted+git@tedbow.com> Date: Tue, 18 Feb 2025 12:49:46 -0500 Subject: [PATCH 8/8] add test coverage for empty title string --- tests/src/Kernel/ApiAutoSaveControllerTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/src/Kernel/ApiAutoSaveControllerTest.php b/tests/src/Kernel/ApiAutoSaveControllerTest.php index 71695210b7..36bd38d81f 100644 --- a/tests/src/Kernel/ApiAutoSaveControllerTest.php +++ b/tests/src/Kernel/ApiAutoSaveControllerTest.php @@ -76,7 +76,11 @@ final class ApiAutoSaveControllerTest extends KernelTestBase { ], ], 'model' => [], - 'entity_form_fields' => [], + 'entity_form_fields' => [ + // Ensure that if the form title is empty, the saved title will be + // returned. + 'title[0][value]' => '', + ], ]; $anonAccountContent = Node::create([ 'type' => 'article', -- GitLab