interface ConfigurableSearchPluginInterface implements ConfigurableInterface, DependentPluginInterface, PluginFormInterface, SearchInterface (View source)

Provides an interface for a configurable Search plugin.

Methods

array
getConfiguration()

Gets this plugin's configuration.

setConfiguration(array $configuration)

Sets the configuration for this plugin instance.

array
defaultConfiguration()

Gets default configuration for this plugin.

array
calculateDependencies()

Calculates dependencies for the configured plugin.

array
buildConfigurationForm(array $form, FormStateInterface $form_state)

Form constructor.

validateConfigurationForm(array $form, FormStateInterface $form_state)

Form validation handler.

submitConfigurationForm(array $form, FormStateInterface $form_state)

Form submission handler.

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.

setSearchPageId(string $search_page_id)

Sets the ID for the search page using this plugin.

Details

array getConfiguration()

Gets this plugin's configuration.

Return Value

array

An array of this plugin's configuration.

setConfiguration(array $configuration)

Sets the configuration for this plugin instance.

Parameters

array $configuration

An associative array containing the plugin's configuration.

array defaultConfiguration()

Gets default configuration for this plugin.

Return Value

array

An associative array with the default configuration.

array calculateDependencies()

Calculates dependencies for the configured plugin.

Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.

Return Value

array

An array of dependencies grouped by type (config, content, module, theme). For example: @code array( 'config' => array('user.role.anonymous', 'user.role.authenticated'), 'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'), 'module' => array('node', 'user'), 'theme' => array('seven'), ); @endcode

See also

ConfigDependencyManager
EntityInterface::getConfigDependencyName

array buildConfigurationForm(array $form, FormStateInterface $form_state)

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and

array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form

An associative array containing the initial structure of the plugin form.

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return Value

array

The form structure.

validateConfigurationForm(array $form, FormStateInterface $form_state)

Form validation handler.

Parameters

array $form

An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

submitConfigurationForm(array $form, FormStateInterface $form_state)

Form submission handler.

Parameters

array $form

An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

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

ConfigurableSearchPluginInterface setSearchPageId(string $search_page_id)

Sets the ID for the search page using this plugin.

Parameters

string $search_page_id

The search page ID.

Return Value

ConfigurableSearchPluginInterface