3 namespace Drupal\search\Plugin;
5 use Drupal\Component\Plugin\PluginInspectionInterface;
6 use Drupal\Core\Form\FormStateInterface;
9 * Defines a common interface for all SearchPlugin objects.
11 interface SearchInterface extends PluginInspectionInterface {
14 * Sets the keywords, parameters, and attributes to be used by execute().
16 * @param string $keywords
17 * The keywords to use in a search.
18 * @param array $parameters
19 * Array of parameters as an associative array. This is expected to
20 * be the query string from the current request.
21 * @param array $attributes
22 * Array of attributes, usually from the current request object.
24 * @return \Drupal\search\Plugin\SearchInterface
25 * A search plugin object for chaining.
27 public function setSearch($keywords, array $parameters, array $attributes);
30 * Returns the currently set keywords of the plugin instance.
35 public function getKeywords();
38 * Returns the current parameters set using setSearch().
43 public function getParameters();
46 * Returns the currently set attributes (from the request).
51 public function getAttributes();
54 * Verifies if the values set via setSearch() are valid and sufficient.
57 * TRUE if the search settings are valid and sufficient to execute a search,
60 public function isSearchExecutable();
63 * Returns the search index type this plugin uses.
66 * The type used by this search plugin in the search index, or NULL if this
67 * plugin does not use the search index.
70 * @see search_index_clear()
72 public function getType();
75 * Executes the search.
78 * A structured list of search results.
80 public function execute();
83 * Executes the search and builds render arrays for the result items.
86 * An array of render arrays of search result items (generally each item
87 * has '#theme' set to 'search_result'), or an empty array if there are no
90 public function buildResults();
93 * Provides a suggested title for a page of search results.
96 * The translated suggested page title.
98 public function suggestedTitle();
101 * Returns the searching help.
104 * Render array for the searching help.
106 public function getHelp();
109 * Alters the search form when being built for a given plugin.
111 * The core search module only invokes this method on active module plugins
112 * when building a form for them in
113 * \Drupal\search\Form\SearchPageForm::buildForm(). A plugin implementing this
114 * will also need to implement the buildSearchUrlQuery() method.
117 * Nested array of form elements that comprise the form.
118 * @param \Drupal\Core\Form\FormStateInterface $form_state
119 * The current state of the form. The arguments that
120 * \Drupal::formBuilder()->getForm() was originally called with are
121 * available in the array $form_state->getBuildInfo()['args'].
123 * @see SearchInterface::buildSearchUrlQuery()
125 public function searchFormAlter(array &$form, FormStateInterface $form_state);
128 * Builds the URL GET query parameters array for search.
130 * When the search form is submitted, a redirect is generated with the
131 * search input as GET query parameters. Plugins using the searchFormAlter()
132 * method to add form elements to the search form will need to override this
133 * method to gather the form input and add it to the GET query parameters.
135 * @param \Drupal\Core\Form\FormStateInterface $form_state
136 * The form state, with submitted form information.
139 * An array of GET query parameters containing all relevant form values
140 * to process the search. The 'keys' element must be present in order to
141 * trigger generation of search results, even if it is empty or unused by
144 * @see SearchInterface::searchFormAlter()
146 public function buildSearchUrlQuery(FormStateInterface $form_state);