diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index 3ef1865..56417e1 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -316,6 +316,7 @@ protected function prepareResults(StatementInterface $found) { $type = $this->entityManager->getStorage('node_type')->load($node->bundle()); unset($build['#theme']); + $build['#pre_render'][] = array($this, 'removeSubmittedInfo'); // Fetch comment count for snippet. $node->rendered = SafeMarkup::set( @@ -357,6 +358,17 @@ protected function prepareResults(StatementInterface $found) { } /** + * Remove the submitted by information from the build array. + * @param array $build + * @return array $build + */ + public function removeSubmittedInfo(array $build) { + unset($build['created']); + unset($build['uid']); + return $build; + } + + /** * Adds the configured rankings to the search query. * * @param $query diff --git a/core/modules/search/src/Tests/SearchExactTest.php b/core/modules/search/src/Tests/SearchExactTest.php index 60855bb..33337d8 100644 --- a/core/modules/search/src/Tests/SearchExactTest.php +++ b/core/modules/search/src/Tests/SearchExactTest.php @@ -18,7 +18,8 @@ class SearchExactTest extends SearchTestBase { */ function testExactQuery() { // Login with sufficient privileges. - $this->drupalLogin($this->drupalCreateUser(array('create page content', 'search content'))); + $user = $this->drupalCreateUser(array('create page content', 'search content')); + $this->drupalLogin($user); $settings = array( 'type' => 'page', @@ -34,6 +35,9 @@ function testExactQuery() { $settings['body'] = array(array('value' => 'love cheesy pizza')); $this->drupalCreateNode($settings); } + // Create another node and save it for later. + $settings['body'] = array(array('value' => 'Druplicon')); + $node = $this->drupalCreateNode($settings); // Update the search index. $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); @@ -55,5 +59,24 @@ function testExactQuery() { $this->drupalPostForm('search/node', $edit, t('Search')); $this->assertLinkByHref('page=1', 0, '2nd page link is found for exact phrase search.'); $this->assertNoLinkByHref('page=2', '3rd page link is not found for exact phrase search.'); + + // Check that with post settings turned on the post information is displayed. + $node_type_config = \Drupal::configFactory()->getEditable('node.type.page'); + $node_type_config->set('display_submitted', TRUE); + $node_type_config->save(); + + $edit = array('keys' => 'Druplicon'); + $this->drupalPostForm('search/node', $edit, t('Search')); + $this->assertText($user->getUsername(), 'Basic page node displays author name when post settings are on.'); + $this->assertText(format_date($node->getChangedTime(), 'short'), 'Basic page node displays post date when post settings are on.'); + + // Check that with post settings turned off the post information is not displayed. + $node_type_config->set('display_submitted', FALSE); + $node_type_config->save(); + $edit = array('keys' => 'Druplicon'); + $this->drupalPostForm('search/node', $edit, t('Search')); + $this->assertNoText($user->getUsername(), 'Basic page node does not display author name when post settings are off.'); + $this->assertNoText(format_date($node->getChangedTime(), 'short'), 'Basic page node does not display post date when post settings are off.'); + } }