Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
google_json_api
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
google_json_api
Commits
3c07709a
Commit
3c07709a
authored
1 year ago
by
Sam Lerner
Committed by
Timothy Zura
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3366262
by SamLerner: Missing search keys results in error
parent
1ab515f5
No related branches found
Branches containing commit
Tags
1.4.0
Tags containing commit
1 merge request
!6
Updates the 'no keywords' template to not error out when no keywords are provided.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/TwigExtension/HighlightSearchTerm.php
+5
-5
5 additions, 5 deletions
src/TwigExtension/HighlightSearchTerm.php
templates/google_json_api_no_keywords_message.html.twig
+1
-1
1 addition, 1 deletion
templates/google_json_api_no_keywords_message.html.twig
with
6 additions
and
6 deletions
src/TwigExtension/HighlightSearchTerm.php
+
5
−
5
View file @
3c07709a
...
...
@@ -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
* H
tml
as string.
* H
TML 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
;
...
...
This diff is collapsed.
Click to expand it.
templates/google_json_api_no_keywords_message.html.twig
+
1
−
1
View file @
3c07709a
<div
class=
"gjas-results-no-keywords--message"
>
{{
highlight_search
(
message
,
term
)
}}
{{
message
}}
</div>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment