public function LinkitSearchPluginEntity::fetchResults in Linkit 7.3
Implements LinkitSearchPluginInterface::fetchResults().
Overrides LinkitSearchPluginInterface::fetchResults
1 call to LinkitSearchPluginEntity::fetchResults()
- LinkitSearchPluginTaxonomy_term::fetchResults in plugins/
linkit_search/ taxonomy_term.class.php - Overrides LinkitSearchPluginEntity::fetchResults().
1 method overrides LinkitSearchPluginEntity::fetchResults()
- LinkitSearchPluginTaxonomy_term::fetchResults in plugins/
linkit_search/ taxonomy_term.class.php - Overrides LinkitSearchPluginEntity::fetchResults().
File
- plugins/
linkit_search/ entity.class.php, line 204 - Define Linkit entity search plugin class.
Class
- LinkitSearchPluginEntity
- Represents a Linkit entity search plugin.
Code
public function fetchResults($search_string) {
// If the $search_string is not a string, something is wrong and an empty
// array is returned.
$matches = array();
// Get the EntityFieldQuery instance.
$this
->getQueryInstance();
// Add the search condition to the query object.
$this->query
->propertyCondition($this->entity_field_label, '%' . db_like($search_string) . '%', 'LIKE')
->addTag('linkit_entity_autocomplete')
->addTag('linkit_' . $this->plugin['entity_type'] . '_autocomplete');
// Add access tag for the query.
// There is also a runtime access check that uses entity_access().
$this->query
->addTag($this->plugin['entity_type'] . '_access');
// Bundle check.
if (isset($this->entity_key_bundle) && isset($this->conf['bundles'])) {
$bundles = array_filter($this->conf['bundles']);
if ($bundles) {
$this->query
->propertyCondition($this->entity_key_bundle, $bundles, 'IN');
}
}
// Execute the query.
$result = $this->query
->execute();
if (!isset($result[$this->plugin['entity_type']])) {
return array();
}
$ids = array_keys($result[$this->plugin['entity_type']]);
// Load all the entities with all the ids we got.
$entities = entity_load($this->plugin['entity_type'], $ids);
foreach ($entities as $entity) {
// Check the access against the defined entity access callback.
if (entity_access('view', $this->plugin['entity_type'], $entity) === FALSE) {
continue;
}
$matches[] = array(
'title' => $this
->createLabel($entity),
'description' => $this
->createDescription($entity),
'path' => $this
->createPath($entity),
'group' => $this
->createGroup($entity),
'addClass' => $this
->createRowClass($entity),
);
}
return $matches;
}