Skip to content
Snippets Groups Projects
Commit 3c07709a authored by Sam Lerner's avatar Sam Lerner Committed by Timothy Zura
Browse files

Issue #3366262 by SamLerner: Missing search keys results in error

parent 1ab515f5
No related branches found
Tags 1.4.0
1 merge request!6Updates the 'no keywords' template to not error out when no keywords are provided.
......@@ -22,7 +22,7 @@ class HighlightSearchTerm extends AbstractExtension {
*
* The value is a standard PHP callback that defines what the function does.
*/
public function getFunctions() {
public function getFunctions(): array {
return [new TwigFunction('highlight_search', [$this, 'highlightSearch'])];
}
......@@ -32,7 +32,7 @@ class HighlightSearchTerm extends AbstractExtension {
* @return string
* A unique identifier for this Twig extension.
*/
public function getName() {
public function getName(): string {
return 'google_json_api.highlight_search_term';
}
......@@ -40,11 +40,11 @@ class HighlightSearchTerm extends AbstractExtension {
* Function to bold search terms in a snippet of text.
*
* @param string $string
* Html as string.
* HTML of search result as string.
* @param string $term
* The search term.
* The search term to highlight.
*/
public static function highlightSearch($string, $term) {
public static function highlightSearch(string $string, string $term): void {
$bold_term = '<strong>' . $term . '</strong>';
$new_string = '<span>' . str_ireplace($term, $bold_term, $string) . '</span>';
echo $new_string;
......
<div class="gjas-results-no-keywords--message">
{{ highlight_search(message, term) }}
{{ message }}
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment