abstract class SearchPluginBase in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/search/src/Plugin/SearchPluginBase.php \Drupal\search\Plugin\SearchPluginBase
Defines a base class for plugins wishing to support search.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\search\Plugin\SearchPluginBase implements RefinableCacheableDependencyInterface, ContainerFactoryPluginInterface, SearchInterface uses RefinableCacheableDependencyTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of SearchPluginBase
1 file declares its use of SearchPluginBase
- UserSearch.php in core/
modules/ user/ src/ Plugin/ Search/ UserSearch.php - Contains \Drupal\user\Plugin\Search\UserSearch.
File
- core/
modules/ search/ src/ Plugin/ SearchPluginBase.php, line 21 - Contains \Drupal\search\Plugin\SearchPluginBase.
Namespace
Drupal\search\PluginView source
abstract class SearchPluginBase extends PluginBase implements ContainerFactoryPluginInterface, SearchInterface, RefinableCacheableDependencyInterface {
use RefinableCacheableDependencyTrait;
/**
* The keywords to use in a search.
*
* @var string
*/
protected $keywords;
/**
* Array of parameters from the query string from the request.
*
* @var array
*/
protected $searchParameters;
/**
* Array of attributes - usually from the request object.
*
* @var array
*/
protected $searchAttributes;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function setSearch($keywords, array $parameters, array $attributes) {
$this->keywords = (string) $keywords;
$this->searchParameters = $parameters;
$this->searchAttributes = $attributes;
return $this;
}
/**
* {@inheritdoc}
*/
public function getKeywords() {
return $this->keywords;
}
/**
* {@inheritdoc}
*/
public function getParameters() {
return $this->searchParameters;
}
/**
* {@inheritdoc}
*/
public function getAttributes() {
return $this->searchAttributes;
}
/**
* {@inheritdoc}
*/
public function isSearchExecutable() {
// Default implementation suitable for plugins that only use keywords.
return !empty($this->keywords);
}
/**
* {@inheritdoc}
*/
public function getType() {
return NULL;
}
/**
* {@inheritdoc}
*/
public function buildResults() {
$results = $this
->execute();
$built = array();
foreach ($results as $result) {
$built[] = array(
'#theme' => 'search_result',
'#result' => $result,
'#plugin_id' => $this
->getPluginId(),
);
}
return $built;
}
/**
* {@inheritdoc}
*/
public function searchFormAlter(array &$form, FormStateInterface $form_state) {
// Empty default implementation.
}
/**
* {@inheritdoc}
*/
public function suggestedTitle() {
// If the user entered a search string, truncate it and append it to the
// title.
if (!empty($this->keywords)) {
return $this
->t('Search for @keywords', array(
'@keywords' => Unicode::truncate($this->keywords, 60, TRUE, TRUE),
));
}
// Use the default 'Search' title.
return $this
->t('Search');
}
/*
* {@inheritdoc}
*/
public function buildSearchUrlQuery(FormStateInterface $form_state) {
// Grab the keywords entered in the form and put them as 'keys' in the GET.
$keys = trim($form_state
->getValue('keys'));
$query = array(
'keys' => $keys,
);
return $query;
}
/*
* {@inheritdoc}
*/
public function getHelp() {
// This default search help is appropriate for plugins like NodeSearch
// that use the SearchQuery class.
$help = array(
'list' => array(
'#theme' => 'item_list',
'#items' => array(
$this
->t('Search looks for exact, case-insensitive keywords; keywords shorter than a minimum length are ignored.'),
$this
->t('Use upper-case OR to get more results. Example: cat OR dog (content contains either "cat" or "dog").'),
$this
->t('You can use upper-case AND to require all words, but this is the same as the default behavior. Example: cat AND dog (same as cat dog, content must contain both "cat" and "dog").'),
$this
->t('Use quotes to search for a phrase. Example: "the cat eats mice".'),
$this
->t('You can precede keywords by - to exclude them; you must still have at least one "positive" keyword. Example: cat -dog (content must contain cat and cannot contain dog).'),
),
),
);
return $help;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 2 |
PluginBase:: |
protected | property | The plugin implementation definition. | |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Constructs a Drupal\Component\Plugin\PluginBase object. | 69 |
RefinableCacheableDependencyTrait:: |
protected | property | Cache contexts. | |
RefinableCacheableDependencyTrait:: |
protected | property | Cache max-age. | |
RefinableCacheableDependencyTrait:: |
protected | property | Cache tags. | |
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | 4 | |
RefinableCacheableDependencyTrait:: |
public | function | 4 | |
RefinableCacheableDependencyTrait:: |
public | function | 4 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
SearchInterface:: |
public | function | Executes the search. | 3 |
SearchPluginBase:: |
protected | property | The keywords to use in a search. | |
SearchPluginBase:: |
protected | property | Array of attributes - usually from the request object. | |
SearchPluginBase:: |
protected | property | Array of parameters from the query string from the request. | |
SearchPluginBase:: |
public | function |
Executes the search and builds render arrays for the result items. Overrides SearchInterface:: |
1 |
SearchPluginBase:: |
public | function |
Builds the URL GET query parameters array for search. Overrides SearchInterface:: |
1 |
SearchPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
SearchPluginBase:: |
public | function |
Returns the currently set attributes (from the request). Overrides SearchInterface:: |
|
SearchPluginBase:: |
public | function |
Returns the searching help. Overrides SearchInterface:: |
1 |
SearchPluginBase:: |
public | function |
Returns the currently set keywords of the plugin instance. Overrides SearchInterface:: |
|
SearchPluginBase:: |
public | function |
Returns the current parameters set using setSearch(). Overrides SearchInterface:: |
|
SearchPluginBase:: |
public | function |
Returns the search index type this plugin uses. Overrides SearchInterface:: |
1 |
SearchPluginBase:: |
public | function |
Verifies if the values set via setSearch() are valid and sufficient. Overrides SearchInterface:: |
2 |
SearchPluginBase:: |
public | function |
Alters the search form when being built for a given plugin. Overrides SearchInterface:: |
1 |
SearchPluginBase:: |
public | function |
Sets the keywords, parameters, and attributes to be used by execute(). Overrides SearchInterface:: |
1 |
SearchPluginBase:: |
public | function |
Provides a suggested title for a page of search results. Overrides SearchInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |