backend_entity_autocomplete
Triggered during the search used for adding a tag-like link with the # character to the task description or to a comment. Allows modifying the search query text and its results as well as adding search by objects provided by other apps not supported by Teamwork.
Teamwork
Input (passed by reference)
$params['term'] string Text typed by a user after the # character, which is used to search for objects in installed apps.
$params['limit'] int Maximum number of search results that can be shown.
$params['limit'] int Maximum number of search results that can be shown.
… your plugin code …
Output
$return
The list of search results items. Each list item is an array with the following keys:
[]['app_id'] string Identifier of the app whose object has been found by the search.
[]['entity_type'] string Found object’s type.
[]['entity_title'] string Localized object name.
[]['entity_url'] string Relative URL of the link pointing to the found object.
[]['app_id'] string Identifier of the app whose object has been found by the search.
[]['entity_type'] string Found object’s type.
[]['entity_title'] string Localized object name.
[]['entity_url'] string Relative URL of the link pointing to the found object.
Teamwork
Plugin code example
PHP
public function backendEntityAutocomplete(&$params)
{
$term = &$params['term'];
// Modify the term here if necessary; e.g., correct typos.
// tasksMyPluginHelper::fixTypo($term);
// Enable access to Site app's classes.
wa('site');
// E.g., search for Site app pages by their names.
$site_pages_model = new sitePageModel();
$pages = $site_pages_model
->select('id, name')
->where(
'name LIKE s:term',
[
'term' => sprintf(
'%%%s%%',
$site_pages_model->escape($term, 'like')
)
]
)
->fetchAll();
if ($pages) {
$backend_url = wa()->getConfig()->getBackendUrl();
return array_map(
function ($page) use ($backend_url) {
return [
'app_id' => 'site',
'entity_type' => 'page',
'entity_url' => sprintf(
'/%s/site/#/pages/%d',
$backend_url,
$page['id']
),
'entity_title' => $page['name'],
];
},
$pages
);
}
}









