interface SearchInterface implements PluginInspectionInterface (View source)

Defines a common interface for all SearchPlugin objects.

Methods

string
getPluginId()

Gets the plugin_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

$this
setSearch(string $keywords, array $parameters, array $attributes)

Sets the keywords, parameters, and attributes to be used by execute().

string
getKeywords()

Returns the currently set keywords of the plugin instance.

array
getParameters()

Returns the current parameters set using setSearch().

array
getAttributes()

Returns the currently set attributes (from the request).

bool
isSearchExecutable()

Verifies if the values set via setSearch() are valid and sufficient.

string|null
getType()

Returns the search index type this plugin uses.

array
execute()

Executes the search.

array
buildResults()

Executes the search and builds render arrays for the result items.

string
suggestedTitle()

Provides a suggested title for a page of search results.

array
getHelp()

Returns the searching help.

searchFormAlter(array $form, FormStateInterface $form_state)

Alters the search form when being built for a given plugin.

array
buildSearchUrlQuery(FormStateInterface $form_state)

Builds the URL GET query parameters array for search.

bool
usesAdminTheme()

Returns whether or not search results should be displayed in admin theme.

Details

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

$this setSearch(string $keywords, array $parameters, array $attributes)

Sets the keywords, parameters, and attributes to be used by execute().

Parameters

string $keywords

The keywords to use in a search.

array $parameters

Array of parameters as an associative array. This is expected to be the query string from the current request.

array $attributes

Array of attributes, usually from the current request object.

Return Value

$this

A search plugin object for chaining.

string getKeywords()

Returns the currently set keywords of the plugin instance.

Return Value

string

The keywords.

array getParameters()

Returns the current parameters set using setSearch().

Return Value

array

The parameters.

array getAttributes()

Returns the currently set attributes (from the request).

Return Value

array

The attributes.

bool isSearchExecutable()

Verifies if the values set via setSearch() are valid and sufficient.

Return Value

bool

TRUE if the search settings are valid and sufficient to execute a search, and FALSE if not.

string|null getType()

Returns the search index type this plugin uses.

Return Value

string|null

The type used by this search plugin in the search index, or NULL if this plugin does not use the search index.

See also

SearchIndexInterface::index
SearchIndexInterface::clear

array execute()

Executes the search.

Return Value

array

A structured list of search results.

array buildResults()

Executes the search and builds render arrays for the result items.

Return Value

array

An array of render arrays of search result items (generally each item has '#theme' set to 'search_result'), or an empty array if there are no results.

string suggestedTitle()

Provides a suggested title for a page of search results.

Return Value

string

The translated suggested page title.

array getHelp()

Returns the searching help.

Return Value

array

Render array for the searching help.

searchFormAlter(array $form, FormStateInterface $form_state)

Alters the search form when being built for a given plugin.

The core search module only invokes this method on active module plugins when building a form for them in \Drupal\search\Form\SearchPageForm::buildForm(). A plugin implementing this will also need to implement the buildSearchUrlQuery() method.

Parameters

array $form

Nested array of form elements that comprise the form.

FormStateInterface $form_state

The current state of the form. The arguments that \Drupal::formBuilder()->getForm() was originally called with are available in the array $form_state->getBuildInfo()['args'].

See also

SearchInterface::buildSearchUrlQuery

array buildSearchUrlQuery(FormStateInterface $form_state)

Builds the URL GET query parameters array for search.

When the search form is submitted, a redirect is generated with the search input as GET query parameters. Plugins using the searchFormAlter() method to add form elements to the search form will need to override this method to gather the form input and add it to the GET query parameters.

Parameters

FormStateInterface $form_state

The form state, with submitted form information.

Return Value

array

An array of GET query parameters containing all relevant form values to process the search. The 'keys' element must be present in order to trigger generation of search results, even if it is empty or unused by the search plugin.

See also

SearchInterface::searchFormAlter

bool usesAdminTheme()

Returns whether or not search results should be displayed in admin theme.

Return Value

bool

TRUE if search results should be displayed in the admin theme, and FALSE otherwise.

See also

SearchPlugin::$use_admin_theme