diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index 0fc7c5824a6c402b63ecd1d8c3080452ff1e67fc..c9f12ec4797ecb66408af9357bf075941c4931e0 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -154,30 +154,10 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { // Reindex the node when it is updated. The node is automatically indexed // when it is added, simply by being added to the node table. if ($update) { - $this->nodeSearchRemoveDeletedTranslations(); node_reindex_node_search($this->id()); } } - /** - * Remove deleted translations from the search index. - * - * @return bool - * TRUE if a translation was removed, FALSE otherwise. - */ - private function nodeSearchRemoveDeletedTranslations(): bool { - $removed = FALSE; - if (\Drupal::moduleHandler()->moduleExists('search')) { - foreach ($this->translations as $langcode => $translation) { - if ($translation['status'] === static::TRANSLATION_REMOVED) { - \Drupal::service('search.index')->clear('node_search', $this->id(), $langcode); - $removed = TRUE; - } - } - } - return $removed; - } - /** * {@inheritdoc} */ diff --git a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php index 138e94770d00fbb1f990ea90ca78041eaa041009..33fd1e33f9aea9cd3976238a6e476a0e888aa767 100644 --- a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php +++ b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php @@ -616,66 +616,4 @@ public function testUrlPrefixOnLanguageNeutralContent() { } } - /** - * Test deletion of translated content from search and index rebuild. - */ - public function testSearchIndexRebuildOnTranslationDeletion(): void { - \Drupal::service('module_installer')->install(['search']); - $admin_user = $this->drupalCreateUser([ - 'administer site configuration', - 'access administration pages', - 'administer content types', - 'delete content translations', - 'administer content translation', - 'translate any entity', - 'administer search', - 'search content', - 'delete any article content', - ]); - $this->drupalLogin($admin_user); - - // Create a node. - $node = $this->drupalCreateNode([ - 'type' => $this->bundle, - ]); - - // Add a French translation. - $translation = $node->addTranslation('fr'); - $translation->title = 'First rev fr title'; - $translation->setNewRevision(FALSE); - $translation->save(); - - // Check if 1 page is listed for indexing. - $this->drupalGet('admin/config/search/pages'); - $this->assertSession()->pageTextContains('There is 1 item left to index.'); - - // Run cron. - $this->drupalGet('admin/config/system/cron'); - $this->getSession()->getPage()->pressButton('Run cron'); - - // Assert no items are left for indexing. - $this->drupalGet('admin/config/search/pages'); - $this->assertSession()->pageTextContains('There are 0 items left to index.'); - - // Search for French content. - $this->drupalGet('search/node', ['query' => ['keys' => urlencode('First rev fr title')]]); - $this->assertSession()->pageTextContains('First rev fr title'); - - // Delete translation. - $this->drupalGet('fr/node/' . $node->id() . '/delete'); - $this->getSession()->getPage()->pressButton('Delete French translation'); - - // Run cron. - $this->drupalGet('admin/config/system/cron'); - $this->getSession()->getPage()->pressButton('Run cron'); - - // Assert no items are left for indexing. - $this->drupalGet('admin/config/search/pages'); - $this->assertSession()->pageTextContains('There are 0 items left to index.'); - - // Search for French content. - $this->drupalGet('search/node', ['query' => ['keys' => urlencode('First rev fr title')]]); - $this->assertSession()->pageTextNotContains('First rev fr title'); - } - }