Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frontend_routing
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
frontend_routing
Commits
7afe44be
Commit
7afe44be
authored
11 months ago
by
Jon Minder
Browse files
Options
Downloads
Patches
Plain Diff
Better multilingual support.
parent
03facbb9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Form/SettingsForm.php
+39
-15
39 additions, 15 deletions
src/Form/SettingsForm.php
with
39 additions
and
15 deletions
src/Form/SettingsForm.php
+
39
−
15
View file @
7afe44be
...
@@ -113,7 +113,7 @@ final class SettingsForm extends ConfigFormBase {
...
@@ -113,7 +113,7 @@ final class SettingsForm extends ConfigFormBase {
'#title'
=>
$this
->
t
(
'Node'
),
'#title'
=>
$this
->
t
(
'Node'
),
'#type'
=>
'entity_autocomplete'
,
'#type'
=>
'entity_autocomplete'
,
'#target_type'
=>
'node'
,
'#target_type'
=>
'node'
,
'#required'
=>
$required
,
'#required'
=>
FALSE
,
'#disabled'
=>
!
$required
,
'#disabled'
=>
!
$required
,
'#default_value'
=>
!
empty
(
$nodes
[
$key
])
?
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
load
(
$nodes
[
$key
])
:
NULL
,
'#default_value'
=>
!
empty
(
$nodes
[
$key
])
?
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
load
(
$nodes
[
$key
])
:
NULL
,
];
];
...
@@ -136,7 +136,6 @@ final class SettingsForm extends ConfigFormBase {
...
@@ -136,7 +136,6 @@ final class SettingsForm extends ConfigFormBase {
}
}
$form
[
'bundles'
]
=
[
$form
[
'bundles'
]
=
[
'#title'
=>
$this
->
t
(
'Node Types managed by frontend routing'
),
'#title'
=>
$this
->
t
(
'Node Types managed by frontend routing'
),
'#type'
=>
'checkboxes'
,
'#type'
=>
'checkboxes'
,
...
@@ -285,21 +284,20 @@ final class SettingsForm extends ConfigFormBase {
...
@@ -285,21 +284,20 @@ final class SettingsForm extends ConfigFormBase {
$nodes
=
$this
->
state
->
get
(
'frontend_routing.settings'
)
??
[];
$nodes
=
$this
->
state
->
get
(
'frontend_routing.settings'
)
??
[];
// Update the alias for all related nodes.
// Update the alias for all related nodes.
foreach
(
$nodes
as
$key
=>
$node
)
{
foreach
(
$nodes
as
$key
=>
$node
_id
)
{
if
(
$node
)
{
if
(
$node
_id
)
{
$node
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
load
(
$node
);
$node
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
load
(
$node
_id
);
$aliases
=
!
empty
(
$config
[
$key
][
'aliases'
])
?
$config
[
$key
][
'aliases'
]
:
[];
$aliases
=
!
empty
(
$config
[
$key
][
'aliases'
])
?
$config
[
$key
][
'aliases'
]
:
[];
// First delete the existing alias.
$path
=
'/'
.
$node
->
toUrl
()
->
getInternalPath
();
$results
=
$this
->
entityTypeManager
->
getStorage
(
'path_alias'
)
->
loadByProperties
([
'path'
=>
$path
]);
foreach
(
$results
as
$result
)
{
$result
->
delete
();
}
// Iterate through all languages and check if we have a translation.
// Iterate through all languages and check if we have a translation.
foreach
(
$aliases
as
$language
=>
$alias
)
{
foreach
(
$aliases
as
$language
=>
$alias
)
{
// First delete the existing alias.
$source
=
'/'
.
ltrim
(
$alias
,
'/'
.
$language
);
$results
=
$this
->
entityTypeManager
->
getStorage
(
'path_alias'
)
->
loadByProperties
([
'alias'
=>
$source
]);
foreach
(
$results
as
$result
)
{
$result
->
delete
();
}
if
(
$node
->
hasTranslation
(
$language
))
{
if
(
$node
->
hasTranslation
(
$language
))
{
$node
=
$node
->
getTranslation
(
$language
);
$node
=
$node
->
getTranslation
(
$language
);
}
}
...
@@ -307,14 +305,14 @@ final class SettingsForm extends ConfigFormBase {
...
@@ -307,14 +305,14 @@ final class SettingsForm extends ConfigFormBase {
continue
;
continue
;
}
}
$paths
=
$node
->
get
(
'path'
)
->
getValue
();
$paths
=
$node
->
get
(
'path'
)
->
getValue
();
foreach
(
$paths
as
&
$path
)
{
foreach
(
$paths
as
&
$path
)
{
if
(
$path
[
'langcode'
]
===
$language
)
{
if
(
$path
[
'langcode'
]
===
$language
)
{
// Save the alias and set pathauto to false.
// Save the alias and set pathauto to false.
$alias
=
preg_replace
(
'/^\/'
.
$language
.
'/'
,
''
,
$alias
);
$alias
=
preg_replace
(
'/^\/'
.
$language
.
'/'
,
''
,
$alias
);
$path
[
'alias'
]
=
$alias
;
$path
[
'alias'
]
=
$alias
;
$path
[
'pathauto'
]
=
FALSE
;
$path
[
'pathauto'
]
=
FALSE
;
$node
->
set
(
'path'
,
$paths
);
$this
->
updateAlias
(
$path
,
$node
);
$node
->
save
();
}
}
}
}
}
}
...
@@ -336,4 +334,30 @@ final class SettingsForm extends ConfigFormBase {
...
@@ -336,4 +334,30 @@ final class SettingsForm extends ConfigFormBase {
return
$list
;
return
$list
;
}
}
private
function
updateAlias
(
$path
,
$entity
)
{
$path_alias_storage
=
$this
->
entityTypeManager
->
getStorage
(
'path_alias'
);
$alias_langcode
=
$path
[
'langcode'
];
// If we have an alias, we need to create or update a path alias entity.
if
(
$path
[
'alias'
])
{
if
(
empty
(
$path
[
'pid'
]))
{
$path_alias
=
$path_alias_storage
->
create
([
'path'
=>
'/'
.
$entity
->
toUrl
()
->
getInternalPath
(),
'alias'
=>
$path
[
'alias'
],
'langcode'
=>
$alias_langcode
,
]);
$path_alias
->
save
();
$path
[
'pid'
]
=
$path_alias
->
id
();
}
elseif
(
$path
[
'pid'
])
{
$path_alias
=
$path_alias_storage
->
load
(
$path
[
'pid'
]);
if
(
$path
[
'alias'
]
!=
$path_alias
->
getAlias
())
{
$path_alias
->
setAlias
(
$path
[
'alias'
]);
$path_alias
->
save
();
}
}
}
}
}
}
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