Drupal 8  8.0.2
NodeSearch Class Reference
Inheritance diagram for NodeSearch:

Public Member Functions

 __construct (array $configuration, $plugin_id, $plugin_definition, Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, Config $search_settings, LanguageManagerInterface $language_manager, RendererInterface $renderer, AccountInterface $account=NULL)
 
 access ($operation= 'view', AccountInterface $account=NULL, $return_as_object=FALSE)
 
 isSearchExecutable ()
 
 getType ()
 
 execute ()
 
 removeSubmittedInfo (array $build)
 
 updateIndex ()
 
 indexClear ()
 
 markForReindex ()
 
 indexStatus ()
 
 searchFormAlter (array &$form, FormStateInterface $form_state)
 
 buildSearchUrlQuery (FormStateInterface $form_state)
 
 defaultConfiguration ()
 
 buildConfigurationForm (array $form, FormStateInterface $form_state)
 
 submitConfigurationForm (array &$form, FormStateInterface $form_state)
 
- Public Member Functions inherited from ConfigurableSearchPluginBase
 __construct (array $configuration, $plugin_id, $plugin_definition)
 
 defaultConfiguration ()
 
 getConfiguration ()
 
 setConfiguration (array $configuration)
 
 validateConfigurationForm (array &$form, FormStateInterface $form_state)
 
 calculateDependencies ()
 
 setSearchPageId ($search_page_id)
 
- Public Member Functions inherited from SearchPluginBase
 setSearch ($keywords, array $parameters, array $attributes)
 
 getKeywords ()
 
 getParameters ()
 
 getAttributes ()
 
 isSearchExecutable ()
 
 getType ()
 
 buildResults ()
 
 searchFormAlter (array &$form, FormStateInterface $form_state)
 
 suggestedTitle ()
 
 buildSearchUrlQuery (FormStateInterface $form_state)
 
 getHelp ()
 
- Public Member Functions inherited from PluginInspectionInterface
 getPluginId ()
 
 getPluginDefinition ()
 
- Public Member Functions inherited from RefinableCacheableDependencyInterface
 addCacheContexts (array $cache_contexts)
 
 addCacheTags (array $cache_tags)
 
 mergeCacheMaxAge ($max_age)
 
 addCacheableDependency ($other_object)
 
- Public Member Functions inherited from CacheableDependencyInterface
 getCacheContexts ()
 
 getCacheTags ()
 
 getCacheMaxAge ()
 
- Public Member Functions inherited from PluginFormInterface
 buildConfigurationForm (array $form, FormStateInterface $form_state)
 
 validateConfigurationForm (array &$form, FormStateInterface $form_state)
 
 submitConfigurationForm (array &$form, FormStateInterface $form_state)
 
- Public Member Functions inherited from AccessibleInterface
 access ($operation, AccountInterface $account=NULL, $return_as_object=FALSE)
 

Static Public Member Functions

static create (ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
 
- Static Public Member Functions inherited from SearchPluginBase
static create (ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
 

Data Fields

const ADVANCED_FORM = 'advanced-form'
 

Protected Member Functions

 findResults ()
 
 addNodeRankings (SelectExtender $query)
 
 indexNode (NodeInterface $node)
 
 parseAdvancedDefaults ($f, $keys)
 
 getRankings ()
 

Protected Attributes

 $database
 
 $entityManager
 
 $moduleHandler
 
 $searchSettings
 
 $languageManager
 
 $account
 
 $renderer
 
 $rankings
 
 $advanced
 
- Protected Attributes inherited from ConfigurableSearchPluginBase
 $searchPageId
 
- Protected Attributes inherited from SearchPluginBase
 $keywords
 
 $searchParameters
 
 $searchAttributes
 

Detailed Description

Handles searching for node entities using the Search module index.

( id = "node_search", title = ("Content") )

Constructor & Destructor Documentation

__construct ( array  $configuration,
  $plugin_id,
  $plugin_definition,
Connection  $database,
EntityManagerInterface  $entity_manager,
ModuleHandlerInterface  $module_handler,
Config  $search_settings,
LanguageManagerInterface  $language_manager,
RendererInterface  $renderer,
AccountInterface  $account = NULL 
)

Constructs a object.

Parameters
array$configurationA configuration array containing information about the plugin instance.
string$plugin_idThe plugin_id for the plugin instance.
mixed$plugin_definitionThe plugin implementation definition.
\Drupal\Core\Database\Connection$databaseA database connection object.
\Drupal\Core\Entity\EntityManagerInterface$entity_managerAn entity manager object.
\Drupal\Core\Extension\ModuleHandlerInterface$module_handlerA module manager object.
\Drupal\Core\Config\Config$search_settingsA config object for 'search.settings'.
\Drupal\Core\Language\LanguageManagerInterface$language_managerThe language manager.
\Drupal\Core\Session\AccountInterface$accountThe $account object to use for checking for access to advanced search.

References RefinableCacheableDependencyInterface\addCacheTags(), Drupal\database(), Drupal\entityManager(), Drupal\languageManager(), and Drupal\moduleHandler().

Here is the call graph for this function:

Member Function Documentation

access (   $operation = 'view',
AccountInterface  $account = NULL,
  $return_as_object = FALSE 
)

{}

References AccessResult\allowedIfHasPermission().

Here is the call graph for this function:

addNodeRankings ( SelectExtender  $query)
protected

Adds the configured rankings to the search query.

Parameters
$queryA query object that has been extended with the Search DB Extender.

References NodeSearch\getRankings().

Referenced by NodeSearch\findResults().

Here is the call graph for this function:

Here is the caller graph for this function:

buildConfigurationForm ( array  $form,
FormStateInterface  $form_state 
)

{}

References NodeSearch\getRankings(), and t().

Here is the call graph for this function:

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
\Drupal\Core\Form\FormStateInterface$form_stateThe form state, with submitted form information.
Returns
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()

Implements SearchInterface.

static create ( ContainerInterface  $container,
array  $configuration,
  $plugin_id,
  $plugin_definition 
)
static

{Creates an instance of the plugin.

Parameters
\Symfony\Component\DependencyInjection\ContainerInterface$containerThe container to pull out services used in the plugin.
array$configurationA configuration array containing information about the plugin instance.
string$plugin_idThe plugin ID for the plugin instance.
mixed$plugin_definitionThe plugin implementation definition.
Returns
static Returns an instance of this plugin.
}

Implements ContainerFactoryPluginInterface.

defaultConfiguration ( )

{Gets default configuration for this plugin.

Returns
array An associative array with the default configuration.
}

Implements ConfigurablePluginInterface.

execute ( )

{Executes the search.

Returns
array A structured list of search results.
}

Implements SearchInterface.

References NodeSearch\findResults(), and NodeSearch\isSearchExecutable().

Here is the call graph for this function:

findResults ( )
protected

Queries to find search results, and sets status messages.

This method can assume that $this->isSearchExecutable() has already been checked and returned TRUE.

Returns
|null Results from search query execute() method, or NULL if the search failed.

References NodeSearch\addNodeRankings(), Drupal\database(), SearchPluginBase\getParameters(), PluginInspectionInterface\getPluginId(), and t().

Referenced by NodeSearch\execute().

Here is the call graph for this function:

Here is the caller graph for this function:

getRankings ( )
protected

Gathers ranking definitions from hook_ranking().

Returns
array An array of ranking definitions.

References Drupal\moduleHandler().

Referenced by NodeSearch\addNodeRankings(), NodeSearch\buildConfigurationForm(), and NodeSearch\submitConfigurationForm().

Here is the call graph for this function:

Here is the caller graph for this function:

getType ( )

{Returns the search index type this plugin uses.

Returns
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
search_index()
search_index_clear()
}

Implements SearchInterface.

References PluginInspectionInterface\getPluginId().

Here is the call graph for this function:

indexClear ( )

{Clears the search index for this plugin.When a request is made to clear all items from the search index related to this plugin, this method will be called. If this plugin uses the default search index, this method can call search_index_clear($type) to remove indexed items from the search database.

See Also
search_index_clear()
}

Implements SearchIndexingInterface.

References PluginInspectionInterface\getPluginId().

Here is the call graph for this function:

indexNode ( NodeInterface  $node)
protected

Indexes a single node.

Parameters
\Drupal\node\NodeInterface$nodeThe node to index.

References Drupal\entityManager(), PluginInspectionInterface\getPluginId(), TranslatableInterface\getTranslation(), TranslatableInterface\getTranslationLanguages(), EntityInterface\id(), EntityInterface\label(), and Drupal\moduleHandler().

Referenced by NodeSearch\updateIndex().

Here is the call graph for this function:

Here is the caller graph for this function:

indexStatus ( )

{Reports the status of indexing.The core search module only invokes this method on active module plugins. Implementing modules do not need to check whether they are active when calculating their return values.

Returns
array An associative array with the key-value pairs:
  • remaining: The number of items left to index.
  • total: The total number of items to index.
}

Implements SearchIndexingInterface.

References Drupal\database(), and PluginInspectionInterface\getPluginId().

Here is the call graph for this function:

isSearchExecutable ( )

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

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

Implements SearchInterface.

Referenced by NodeSearch\execute().

Here is the caller graph for this function:

markForReindex ( )

{Marks the search index for reindexing for this plugin.When a request is made to mark all items from the search index related to this plugin for reindexing, this method will be called. If this plugin uses the default search index, this method can call search_mark_for_reindex($type) to mark the items in the search database for reindexing.

See Also
search_mark_for_reindex()
}

Implements SearchIndexingInterface.

References PluginInspectionInterface\getPluginId().

Here is the call graph for this function:

parseAdvancedDefaults (   $f,
  $keys 
)
protected

Parses the advanced search form default values.

Parameters
array$fThe 'f' query parameter set up in self::buildUrlSearchQuery(), which contains the advanced query values.
string$keysThe search keywords string, which contains some information from the advanced search form.
Returns
array Array of default form values for the advanced search form, including a modified 'keys' element for the bare search keywords.

Referenced by NodeSearch\searchFormAlter().

Here is the caller graph for this function:

removeSubmittedInfo ( array  $build)

Removes the submitted by information from the build array.

This information is being removed from the rendered node that is used to build the search result snippet. It just doesn't make sense to have it displayed in the snippet.

Parameters
array$buildThe build array.
Returns
array The modified build array.
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 ::form(). A plugin implementing this will also need to implement the buildSearchUrlQuery() method.

Parameters
array$formNested array of form elements that comprise the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form. The arguments that ::formBuilder()->getForm() was originally called with are available in the array $form_state->getBuildInfo()['args'].
See Also
SearchInterface::buildSearchUrlQuery()
}

Implements SearchInterface.

References SearchPluginBase\getKeywords(), SearchPluginBase\getParameters(), Drupal\languageManager(), NodeSearch\parseAdvancedDefaults(), LanguageInterface\STATE_ALL, and t().

Here is the call graph for this function:

submitConfigurationForm ( array &  $form,
FormStateInterface  $form_state 
)

{}

References NodeSearch\getRankings().

Here is the call graph for this function:

updateIndex ( )

{Updates the search index for this plugin.This method is called every cron run if the plugin has been set as an active search module on the Search settings page (admin/config/search/pages). It allows your module to add items to the built-in search index using search_index(), or to add them to your module's own indexing mechanism.When implementing this method, your module should index content items that were modified or added since the last run. There is a time limit for cron, so it is advisable to limit how many items you index per run using config('search.settings')->get('index.cron_limit') or with your own setting. And since the cron run could time out and abort in the middle of your run, you should update any needed internal bookkeeping on when items have last been indexed as you go rather than waiting to the end of indexing.}

Implements SearchIndexingInterface.

References Drupal\database(), Drupal\entityManager(), PluginInspectionInterface\getPluginId(), and NodeSearch\indexNode().

Here is the call graph for this function:

Field Documentation

$advanced
protected
Initial value:
= array(
'type' => array('column' => 'n.type'),
'language' => array('column' => 'i.langcode'),
'author' => array('column' => 'n.uid'),
'term' => array('column' => 'ti.tid', 'join' => array('table' => 'taxonomy_index', 'alias' => 'ti', 'condition' => 'n.nid = ti.nid')),
)
const ADVANCED_FORM = 'advanced-form'

A constant for setting and checking the query string.


The documentation for this class was generated from the following file: