Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dynamic_path_aliases
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
dynamic_path_aliases
Commits
474e3a6d
Commit
474e3a6d
authored
2 years ago
by
Robert Phillips
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3323856
by robphillips: Autocomplete controller to lookup routes.
parent
d2c9ec9c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dynamic_path_aliases.routing.yml
+7
-0
7 additions, 0 deletions
dynamic_path_aliases.routing.yml
src/Controller/PathRewriteAutocompleteController.php
+65
-0
65 additions, 0 deletions
src/Controller/PathRewriteAutocompleteController.php
src/PathRewriteForm.php
+1
-0
1 addition, 0 deletions
src/PathRewriteForm.php
with
73 additions
and
0 deletions
dynamic_path_aliases.routing.yml
0 → 100644
+
7
−
0
View file @
474e3a6d
dynamic_path_aliases.autocomplete
:
path
:
"
/path-rewrite/autocomplete"
defaults
:
_controller
:
Drupal\dynamic_path_aliases\Controller\PathRewriteAutocompleteController::autocomplete
_format
:
json
requirements
:
_permission
:
"
administer
dynamic
path
rewrites"
This diff is collapsed.
Click to expand it.
src/Controller/PathRewriteAutocompleteController.php
0 → 100644
+
65
−
0
View file @
474e3a6d
<?php
namespace
Drupal\dynamic_path_aliases\Controller
;
use
Drupal\Component\Utility\Xss
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\Database\Connection
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* Provides path rewrite route autocomplete controller.
*/
class
PathRewriteAutocompleteController
extends
ControllerBase
{
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected
Connection
$connection
;
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
)
{
$instance
=
parent
::
create
(
$container
);
$instance
->
connection
=
$container
->
get
(
'database'
);
return
$instance
;
}
/**
* Autocomplete callback.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
* Returns JSON response of results.
*/
public
function
autocomplete
(
Request
$request
):
JsonResponse
{
if
(
!
(
$input
=
Xss
::
filter
(
$request
->
query
->
get
(
'q'
))))
{
return
new
JsonResponse
([]);
}
$query
=
$this
->
connection
->
select
(
'router'
)
->
fields
(
'router'
,
[
'name'
,
'path'
])
->
range
(
0
,
10
);
$input
=
'%'
.
$query
->
escapeLike
(
$input
)
.
'%'
;
$query
->
condition
(
$query
->
orConditionGroup
()
->
condition
(
'name'
,
$input
,
'LIKE'
)
->
condition
(
'path'
,
$input
,
'LIKE'
));
$query
->
orderBy
(
'path'
);
$items
=
[];
foreach
(
$query
->
execute
()
as
$result
)
{
$items
[]
=
[
'value'
=>
$result
->
name
,
'label'
=>
$result
->
path
,
];
}
return
new
JsonResponse
(
array_values
(
$items
));
}
}
This diff is collapsed.
Click to expand it.
src/PathRewriteForm.php
+
1
−
0
View file @
474e3a6d
...
...
@@ -78,6 +78,7 @@ class PathRewriteForm extends EntityForm {
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Route name'
),
'#description'
=>
$this
->
t
(
'Route to rewrite its path. Search by route name or path.'
),
'#autocomplete_route_name'
=>
'dynamic_path_aliases.autocomplete'
,
'#required'
=>
TRUE
,
'#default_value'
=>
$this
->
entity
->
get
(
'route_name'
),
];
...
...
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