class SearchExtraTypeSearch
Same name in other branches
- 8.9.x core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php \Drupal\search_extra_type\Plugin\Search\SearchExtraTypeSearch
- 10 core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php \Drupal\search_extra_type\Plugin\Search\SearchExtraTypeSearch
- 11.x core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php \Drupal\search_extra_type\Plugin\Search\SearchExtraTypeSearch
Executes a dummy keyword search.
Plugin annotation
@SearchPlugin(
id = "search_extra_type_search",
title = @Translation("Dummy search type"),
use_admin_theme = TRUE,
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\search\Plugin\SearchPluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\search\Plugin\SearchInterface, \Drupal\Core\Cache\RefinableCacheableDependencyInterface uses \Drupal\Core\Cache\RefinableCacheableDependencyTrait
- class \Drupal\search\Plugin\ConfigurableSearchPluginBase extends \Drupal\search\Plugin\SearchPluginBase implements \Drupal\search\Plugin\ConfigurableSearchPluginInterface
- class \Drupal\search_extra_type\Plugin\Search\SearchExtraTypeSearch extends \Drupal\search\Plugin\ConfigurableSearchPluginBase
- class \Drupal\search\Plugin\ConfigurableSearchPluginBase extends \Drupal\search\Plugin\SearchPluginBase implements \Drupal\search\Plugin\ConfigurableSearchPluginInterface
- class \Drupal\search\Plugin\SearchPluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\search\Plugin\SearchInterface, \Drupal\Core\Cache\RefinableCacheableDependencyInterface uses \Drupal\Core\Cache\RefinableCacheableDependencyTrait
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of SearchExtraTypeSearch
File
-
core/
modules/ search/ tests/ modules/ search_extra_type/ src/ Plugin/ Search/ SearchExtraTypeSearch.php, line 19
Namespace
Drupal\search_extra_type\Plugin\SearchView source
class SearchExtraTypeSearch extends ConfigurableSearchPluginBase {
/**
* {@inheritdoc}
*/
public function setSearch($keywords, array $parameters, array $attributes) {
if (empty($parameters['search_conditions'])) {
$parameters['search_conditions'] = '';
}
parent::setSearch($keywords, $parameters, $attributes);
return $this;
}
/**
* Verifies if the given parameters are valid enough to execute a search for.
*
* @return bool
* TRUE if there are keywords or search conditions in the query.
*/
public function isSearchExecutable() {
return (bool) ($this->keywords || !empty($this->searchParameters['search_conditions']));
}
/**
* Execute the search.
*
* This is a dummy search, so when search "executes", we just return a dummy
* result containing the keywords and a list of conditions.
*
* @return array
* A structured list of search results
*/
public function execute() {
$results = [];
if (!$this->isSearchExecutable()) {
return $results;
}
return [
[
'link' => Url::fromRoute('test_page_test.test_page')->toString(),
'type' => 'Dummy result type',
'title' => 'Dummy title',
'snippet' => new FormattableMarkup("Dummy search snippet to display. Keywords: @keywords\n\nConditions: @search_parameters", [
'@keywords' => $this->keywords,
'@search_parameters' => print_r($this->searchParameters, TRUE),
]),
],
];
}
/**
* {@inheritdoc}
*/
public function buildResults() {
$results = $this->execute();
$output['prefix']['#markup'] = '<h2>Test page text is here</h2> <ol class="search-results">';
foreach ($results as $entry) {
$output[] = [
'#theme' => 'search_result',
'#result' => $entry,
'#plugin_id' => 'search_extra_type_search',
];
}
$pager = [
'#type' => 'pager',
];
$output['suffix']['#markup'] = '</ol>' . \Drupal::service('renderer')->render($pager);
return $output;
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Output form for defining rank factor weights.
$form['extra_type_settings'] = [
'#type' => 'fieldset',
'#title' => $this->t('Extra type settings'),
'#tree' => TRUE,
];
$form['extra_type_settings']['boost'] = [
'#type' => 'select',
'#title' => $this->t('Boost method'),
'#options' => [
'bi' => $this->t('Bistro mathematics'),
'ii' => $this->t('Infinite Improbability'),
],
'#default_value' => $this->configuration['boost'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['boost'] = $form_state->getValue([
'extra_type_settings',
'boost',
]);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'boost' => 'bi',
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
CacheableDependencyTrait::$cacheContexts | protected | property | Cache contexts. | ||
CacheableDependencyTrait::$cacheMaxAge | protected | property | Cache max-age. | ||
CacheableDependencyTrait::$cacheTags | protected | property | Cache tags. | ||
CacheableDependencyTrait::getCacheContexts | public | function | 4 | ||
CacheableDependencyTrait::getCacheMaxAge | public | function | 4 | ||
CacheableDependencyTrait::getCacheTags | public | function | 4 | ||
CacheableDependencyTrait::setCacheability | protected | function | Sets cacheability; useful for value object constructors. | ||
ConfigurableSearchPluginBase::$searchPageId | protected | property | The unique ID for the search page using this plugin. | ||
ConfigurableSearchPluginBase::calculateDependencies | public | function | Calculates dependencies for the configured plugin. | Overrides DependentPluginInterface::calculateDependencies | |
ConfigurableSearchPluginBase::getConfiguration | public | function | Gets this plugin's configuration. | Overrides ConfigurableInterface::getConfiguration | |
ConfigurableSearchPluginBase::setConfiguration | public | function | Sets the configuration for this plugin instance. | Overrides ConfigurableInterface::setConfiguration | |
ConfigurableSearchPluginBase::setSearchPageId | public | function | Sets the ID for the search page using this plugin. | Overrides ConfigurableSearchPluginInterface::setSearchPageId | |
ConfigurableSearchPluginBase::validateConfigurationForm | public | function | Form validation handler. | Overrides PluginFormInterface::validateConfigurationForm | |
ConfigurableSearchPluginBase::__construct | public | function | 1 | ||
PluginInspectionInterface::getPluginDefinition | public | function | Gets the definition of the plugin implementation. | 6 | |
PluginInspectionInterface::getPluginId | public | function | Gets the plugin_id of the plugin instance. | 2 | |
RefinableCacheableDependencyTrait::addCacheableDependency | public | function | 1 | ||
RefinableCacheableDependencyTrait::addCacheContexts | public | function | |||
RefinableCacheableDependencyTrait::addCacheTags | public | function | |||
RefinableCacheableDependencyTrait::mergeCacheMaxAge | public | function | |||
SearchExtraTypeSearch::buildConfigurationForm | public | function | Form constructor. | Overrides PluginFormInterface::buildConfigurationForm | |
SearchExtraTypeSearch::buildResults | public | function | Executes the search and builds render arrays for the result items. | Overrides SearchPluginBase::buildResults | |
SearchExtraTypeSearch::defaultConfiguration | public | function | Gets default configuration for this plugin. | Overrides ConfigurableSearchPluginBase::defaultConfiguration | |
SearchExtraTypeSearch::execute | public | function | Execute the search. | Overrides SearchInterface::execute | |
SearchExtraTypeSearch::isSearchExecutable | public | function | Verifies if the given parameters are valid enough to execute a search for. | Overrides SearchPluginBase::isSearchExecutable | |
SearchExtraTypeSearch::setSearch | public | function | Sets the keywords, parameters, and attributes to be used by execute(). | Overrides SearchPluginBase::setSearch | |
SearchExtraTypeSearch::submitConfigurationForm | public | function | Form submission handler. | Overrides PluginFormInterface::submitConfigurationForm | |
SearchPluginBase::$keywords | protected | property | The keywords to use in a search. | ||
SearchPluginBase::$searchAttributes | protected | property | Array of attributes - usually from the request object. | ||
SearchPluginBase::$searchParameters | protected | property | Array of parameters from the query string from the request. | ||
SearchPluginBase::buildSearchUrlQuery | public | function | Builds the URL GET query parameters array for search. | Overrides SearchInterface::buildSearchUrlQuery | 1 |
SearchPluginBase::create | public static | function | Creates an instance of the plugin. | Overrides ContainerFactoryPluginInterface::create | 3 |
SearchPluginBase::getAttributes | public | function | Returns the currently set attributes (from the request). | Overrides SearchInterface::getAttributes | |
SearchPluginBase::getHelp | public | function | Returns the searching help. | Overrides SearchInterface::getHelp | 1 |
SearchPluginBase::getKeywords | public | function | Returns the currently set keywords of the plugin instance. | Overrides SearchInterface::getKeywords | |
SearchPluginBase::getParameters | public | function | Returns the current parameters set using setSearch(). | Overrides SearchInterface::getParameters | |
SearchPluginBase::getType | public | function | Returns the search index type this plugin uses. | Overrides SearchInterface::getType | 2 |
SearchPluginBase::searchFormAlter | public | function | Alters the search form when being built for a given plugin. | Overrides SearchInterface::searchFormAlter | 1 |
SearchPluginBase::suggestedTitle | public | function | Provides a suggested title for a page of search results. | Overrides SearchInterface::suggestedTitle | |
SearchPluginBase::usesAdminTheme | public | function | Returns whether or not search results should be displayed in admin theme. | Overrides SearchInterface::usesAdminTheme |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.