/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // Redirect to the search page with keywords in the GET parameters. // Plugins with additional search parameters will need to provide their // own form submit handler to replace this, so they can put their values // into the GET as well. If so, make sure to put 'keys' into the GET // parameters so that the search results generation is triggered. $query = $this->entity->getPlugin()->buildSearchUrlQuery($form_state); $route = 'search.view_' . $form_state->get('search_page_id'); $form_state->setRedirect($route, array(), array('query' => $query)); }
/** * Verifies that if we combine two rankings, search still works. * * See issue http://drupal.org/node/771596 */ function testDoubleRankings() { // Login with sufficient privileges. $this->drupalLogin($this->drupalCreateUser(array('skip comment approval', 'create page content'))); // Create two nodes that will match the search, one that is sticky. $settings = array('type' => 'page', 'title' => 'Drupal rocks', 'body' => array(array('value' => "Drupal's search rocks"))); $this->drupalCreateNode($settings); $settings['sticky'] = 1; $node = $this->drupalCreateNode($settings); // Update the search index. $this->nodeSearch->getPlugin()->updateIndex(); search_update_totals(); // Set up for ranking sticky and lots of comments; make sure others are // disabled. $node_ranks = array('sticky', 'promote', 'relevance', 'recent', 'comments', 'views'); $configuration = $this->nodeSearch->getPlugin()->getConfiguration(); foreach ($node_ranks as $var) { $value = $var == 'sticky' || $var == 'comments' ? 10 : 0; $configuration['rankings'][$var] = $value; } $this->nodeSearch->getPlugin()->setConfiguration($configuration); $this->nodeSearch->save(); // Do the search and assert the results. $this->nodeSearch->getPlugin()->setSearch('rocks', array(), array()); // Do the search and assert the results. $set = $this->nodeSearch->getPlugin()->execute(); $this->assertEqual($set[0]['node']->id(), $node->id(), 'Search double ranking order.'); }
/** * Test rankings of HTML tags. */ public function testHTMLRankings() { $full_html_format = entity_create('filter_format', array('format' => 'full_html', 'name' => 'Full HTML')); $full_html_format->save(); // Test HTML tags with different weights. $sorted_tags = array('h1', 'h2', 'h3', 'h4', 'a', 'h5', 'h6', 'notag'); $shuffled_tags = $sorted_tags; // Shuffle tags to ensure HTML tags are ranked properly. shuffle($shuffled_tags); $settings = array('type' => 'page', 'title' => 'Simple node'); $nodes = array(); foreach ($shuffled_tags as $tag) { switch ($tag) { case 'a': $settings['body'] = array(array('value' => \Drupal::l('Drupal Rocks', new Url('<front>')), 'format' => 'full_html')); break; case 'notag': $settings['body'] = array(array('value' => 'Drupal Rocks')); break; default: $settings['body'] = array(array('value' => "<{$tag}>Drupal Rocks</{$tag}>", 'format' => 'full_html')); break; } $nodes[$tag] = $this->drupalCreateNode($settings); } // Update the search index. $this->nodeSearch->getPlugin()->updateIndex(); search_update_totals(); $this->nodeSearch->getPlugin()->setSearch('rocks', array(), array()); // Do the search and assert the results. $set = $this->nodeSearch->getPlugin()->execute(); // Test the ranking of each tag. foreach ($sorted_tags as $tag_rank => $tag) { // Assert the results. if ($tag == 'notag') { $this->assertEqual($set[$tag_rank]['node']->id(), $nodes[$tag]->id(), 'Search tag ranking for plain text order.'); } else { $this->assertEqual($set[$tag_rank]['node']->id(), $nodes[$tag]->id(), 'Search tag ranking for "<' . $sorted_tags[$tag_rank] . '>" order.'); } } // Test tags with the same weight against the sorted tags. $unsorted_tags = array('u', 'b', 'i', 'strong', 'em'); foreach ($unsorted_tags as $tag) { $settings['body'] = array(array('value' => "<{$tag}>Drupal Rocks</{$tag}>", 'format' => 'full_html')); $node = $this->drupalCreateNode($settings); // Update the search index. $this->nodeSearch->getPlugin()->updateIndex(); search_update_totals(); $this->nodeSearch->getPlugin()->setSearch('rocks', array(), array()); // Do the search and assert the results. $set = $this->nodeSearch->getPlugin()->execute(); // Ranking should always be second to last. $set = array_slice($set, -2, 1); // Assert the results. $this->assertEqual($set[0]['node']->id(), $node->id(), 'Search tag ranking for "<' . $tag . '>" order.'); // Delete node so it doesn't show up in subsequent search results. $node->delete(); } }
/** * Performs an operation on the search page entity. * * @param \Drupal\search\SearchPageInterface $search_page * The search page entity. * @param string $op * The operation to perform, usually 'enable' or 'disable'. * * @return \Symfony\Component\HttpFoundation\RedirectResponse * A redirect back to the search settings page. */ public function performOperation(SearchPageInterface $search_page, $op) { $search_page->{$op}()->save(); if ($op == 'enable') { drupal_set_message($this->t('The %label search page has been enabled.', array('%label' => $search_page->label()))); } elseif ($op == 'disable') { drupal_set_message($this->t('The %label search page has been disabled.', array('%label' => $search_page->label()))); } return $this->redirect('search.settings'); }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $this->entity->save(); $form_state->setRedirectUrl($this->entity->urlInfo('collection')); }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $this->entity->save(); $form_state->setRedirect('search.settings'); }
/** * Performs an operation on the search page entity. * * @param \Drupal\search\SearchPageInterface $search_page * The search page entity. * @param string $op * The operation to perform, usually 'enable' or 'disable'. * * @return \Symfony\Component\HttpFoundation\RedirectResponse * A redirect back to the search settings page. */ public function performOperation(SearchPageInterface $search_page, $op) { $search_page->{$op}()->save(); if ($op == 'enable') { drupal_set_message($this->t('The %label search page has been enabled.', array('%label' => $search_page->label()))); } elseif ($op == 'disable') { drupal_set_message($this->t('The %label search page has been disabled.', array('%label' => $search_page->label()))); } $url = $search_page->urlInfo('collection'); return $this->redirect($url->getRouteName(), $url->getRouteParameters(), $url->getOptions()); }
/** * {@inheritdoc} */ public function setDefaultSearchPage(SearchPageInterface $search_page) { $this->configFactory->get('search.settings')->set('default_page', $search_page->id())->save(); $search_page->enable()->save(); }
/** * {@inheritdoc} */ public function save(array $form, array &$form_state) { $this->entity->save(); $form_state['redirect_route']['route_name'] = 'search.settings'; }