Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\search\Plugin;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Plugin\PluginInspectionInterface;
|
Chris@0
|
6 use Drupal\Core\Form\FormStateInterface;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Defines a common interface for all SearchPlugin objects.
|
Chris@0
|
10 */
|
Chris@0
|
11 interface SearchInterface extends PluginInspectionInterface {
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * Sets the keywords, parameters, and attributes to be used by execute().
|
Chris@0
|
15 *
|
Chris@0
|
16 * @param string $keywords
|
Chris@0
|
17 * The keywords to use in a search.
|
Chris@0
|
18 * @param array $parameters
|
Chris@0
|
19 * Array of parameters as an associative array. This is expected to
|
Chris@0
|
20 * be the query string from the current request.
|
Chris@0
|
21 * @param array $attributes
|
Chris@0
|
22 * Array of attributes, usually from the current request object.
|
Chris@0
|
23 *
|
Chris@0
|
24 * @return \Drupal\search\Plugin\SearchInterface
|
Chris@0
|
25 * A search plugin object for chaining.
|
Chris@0
|
26 */
|
Chris@0
|
27 public function setSearch($keywords, array $parameters, array $attributes);
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * Returns the currently set keywords of the plugin instance.
|
Chris@0
|
31 *
|
Chris@0
|
32 * @return string
|
Chris@0
|
33 * The keywords.
|
Chris@0
|
34 */
|
Chris@0
|
35 public function getKeywords();
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * Returns the current parameters set using setSearch().
|
Chris@0
|
39 *
|
Chris@0
|
40 * @return array
|
Chris@0
|
41 * The parameters.
|
Chris@0
|
42 */
|
Chris@0
|
43 public function getParameters();
|
Chris@0
|
44
|
Chris@0
|
45 /**
|
Chris@0
|
46 * Returns the currently set attributes (from the request).
|
Chris@0
|
47 *
|
Chris@0
|
48 * @return array
|
Chris@0
|
49 * The attributes.
|
Chris@0
|
50 */
|
Chris@0
|
51 public function getAttributes();
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@0
|
54 * Verifies if the values set via setSearch() are valid and sufficient.
|
Chris@0
|
55 *
|
Chris@0
|
56 * @return bool
|
Chris@0
|
57 * TRUE if the search settings are valid and sufficient to execute a search,
|
Chris@0
|
58 * and FALSE if not.
|
Chris@0
|
59 */
|
Chris@0
|
60 public function isSearchExecutable();
|
Chris@0
|
61
|
Chris@0
|
62 /**
|
Chris@0
|
63 * Returns the search index type this plugin uses.
|
Chris@0
|
64 *
|
Chris@0
|
65 * @return string|null
|
Chris@0
|
66 * The type used by this search plugin in the search index, or NULL if this
|
Chris@0
|
67 * plugin does not use the search index.
|
Chris@0
|
68 *
|
Chris@0
|
69 * @see search_index()
|
Chris@0
|
70 * @see search_index_clear()
|
Chris@0
|
71 */
|
Chris@0
|
72 public function getType();
|
Chris@0
|
73
|
Chris@0
|
74 /**
|
Chris@0
|
75 * Executes the search.
|
Chris@0
|
76 *
|
Chris@0
|
77 * @return array
|
Chris@0
|
78 * A structured list of search results.
|
Chris@0
|
79 */
|
Chris@0
|
80 public function execute();
|
Chris@0
|
81
|
Chris@0
|
82 /**
|
Chris@0
|
83 * Executes the search and builds render arrays for the result items.
|
Chris@0
|
84 *
|
Chris@0
|
85 * @return array
|
Chris@0
|
86 * An array of render arrays of search result items (generally each item
|
Chris@0
|
87 * has '#theme' set to 'search_result'), or an empty array if there are no
|
Chris@0
|
88 * results.
|
Chris@0
|
89 */
|
Chris@0
|
90 public function buildResults();
|
Chris@0
|
91
|
Chris@0
|
92 /**
|
Chris@0
|
93 * Provides a suggested title for a page of search results.
|
Chris@0
|
94 *
|
Chris@0
|
95 * @return string
|
Chris@0
|
96 * The translated suggested page title.
|
Chris@0
|
97 */
|
Chris@0
|
98 public function suggestedTitle();
|
Chris@0
|
99
|
Chris@0
|
100 /**
|
Chris@0
|
101 * Returns the searching help.
|
Chris@0
|
102 *
|
Chris@0
|
103 * @return array
|
Chris@0
|
104 * Render array for the searching help.
|
Chris@0
|
105 */
|
Chris@0
|
106 public function getHelp();
|
Chris@0
|
107
|
Chris@0
|
108 /**
|
Chris@0
|
109 * Alters the search form when being built for a given plugin.
|
Chris@0
|
110 *
|
Chris@0
|
111 * The core search module only invokes this method on active module plugins
|
Chris@0
|
112 * when building a form for them in
|
Chris@0
|
113 * \Drupal\search\Form\SearchPageForm::buildForm(). A plugin implementing this
|
Chris@0
|
114 * will also need to implement the buildSearchUrlQuery() method.
|
Chris@0
|
115 *
|
Chris@0
|
116 * @param array $form
|
Chris@0
|
117 * Nested array of form elements that comprise the form.
|
Chris@0
|
118 * @param \Drupal\Core\Form\FormStateInterface $form_state
|
Chris@0
|
119 * The current state of the form. The arguments that
|
Chris@0
|
120 * \Drupal::formBuilder()->getForm() was originally called with are
|
Chris@0
|
121 * available in the array $form_state->getBuildInfo()['args'].
|
Chris@0
|
122 *
|
Chris@0
|
123 * @see SearchInterface::buildSearchUrlQuery()
|
Chris@0
|
124 */
|
Chris@0
|
125 public function searchFormAlter(array &$form, FormStateInterface $form_state);
|
Chris@0
|
126
|
Chris@0
|
127 /**
|
Chris@0
|
128 * Builds the URL GET query parameters array for search.
|
Chris@0
|
129 *
|
Chris@0
|
130 * When the search form is submitted, a redirect is generated with the
|
Chris@0
|
131 * search input as GET query parameters. Plugins using the searchFormAlter()
|
Chris@0
|
132 * method to add form elements to the search form will need to override this
|
Chris@0
|
133 * method to gather the form input and add it to the GET query parameters.
|
Chris@0
|
134 *
|
Chris@0
|
135 * @param \Drupal\Core\Form\FormStateInterface $form_state
|
Chris@0
|
136 * The form state, with submitted form information.
|
Chris@0
|
137 *
|
Chris@0
|
138 * @return array
|
Chris@0
|
139 * An array of GET query parameters containing all relevant form values
|
Chris@0
|
140 * to process the search. The 'keys' element must be present in order to
|
Chris@0
|
141 * trigger generation of search results, even if it is empty or unused by
|
Chris@0
|
142 * the search plugin.
|
Chris@0
|
143 *
|
Chris@0
|
144 * @see SearchInterface::searchFormAlter()
|
Chris@0
|
145 */
|
Chris@0
|
146 public function buildSearchUrlQuery(FormStateInterface $form_state);
|
Chris@0
|
147
|
Chris@0
|
148 }
|