Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
5d1ebfdd
Commit
5d1ebfdd
authored
2 years ago
by
Kevin Paxman
Browse files
Options
Downloads
Patches
Plain Diff
ISTWMCS-5866: only do alias stuff if an alias exists (tests were failing)
parent
fb410f22
No related branches found
Branches containing commit
No related tags found
3 merge requests
!286
ISTWCMS-5866 Prevent URL aliases being created for reserved paths
,
!274
Draft: ISTWCMS-5551: fixing office hours display
,
!260
Feature/istwcms 5668 a5kulkar rename references to publications
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uw_cfg_common.module
+47
-46
47 additions, 46 deletions
uw_cfg_common.module
with
47 additions
and
46 deletions
uw_cfg_common.module
+
47
−
46
View file @
5d1ebfdd
...
@@ -851,7 +851,7 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
...
@@ -851,7 +851,7 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
}
}
// Ensure that we are on a UW content type node.
// Ensure that we are on a UW content type node.
if
(
preg_match
(
'/node_uw_ct_.*_form/'
,
$form_id
))
{
if
(
preg_match
(
'/
^
node_uw_ct_.*_form
$
/'
,
$form_id
))
{
// Add custom validation for alias.
// Add custom validation for alias.
$form
[
'#validate'
][]
=
'_uw_cfg_common_alias_validate'
;
$form
[
'#validate'
][]
=
'_uw_cfg_common_alias_validate'
;
...
@@ -938,53 +938,54 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
...
@@ -938,53 +938,54 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
* Validates submission values for alias on nodes.
* Validates submission values for alias on nodes.
*/
*/
function
_uw_cfg_common_alias_validate
(
array
&
$form
,
FormStateInterface
$form_state
):
void
{
function
_uw_cfg_common_alias_validate
(
array
&
$form
,
FormStateInterface
$form_state
):
void
{
if
(
isset
(
$values
[
'path'
][
0
][
'alias'
]))
{
// List of urls which should not be an alias.
$urls
=
[
'blog'
,
'events'
,
'news'
,
'projects'
,
'profile'
,
'profiles'
,
'contacts'
,
'service'
,
'opportunities'
,
'user'
,
'users'
,
];
// List of urls which should not be an alias.
// Get the values from the form state.
$urls
=
[
$values
=
$form_state
->
getValues
();
'blog'
,
'events'
,
// Get the alias from the form state values.
'news'
,
$alias
=
$values
[
'path'
][
0
][
'alias'
];
'projects'
,
$orig_alias
=
$alias
;
'profile'
,
'profiles'
,
// Trim any surrounding slashes from the alias to
'contacts'
,
// ensure that we are getting exact matches for the
'service'
,
// predefined alias from above. Some users will add
'opportunities'
,
// slashes before and after the alias, so just
'user'
,
// easier to check without slashes.
'users'
,
$alias
=
trim
(
$alias
,
'/'
);
];
// Check if the alias exists if yes, sets error.
// Get the values from the form state.
// We are checking three cases, the first is if
$values
=
$form_state
->
getValues
();
// the alias is in the predefined list. The second
// is if the alias is just /, or just a series of slashes,
// Get the alias from the form state values.
// we have to check here because we removed all the
$alias
=
$values
[
'path'
][
0
][
'alias'
];
// slashes with the alias variable. The last is to check
$orig_alias
=
$alias
;
// if the alias has any form of strictly admin, so /admin/,
// admin, admin/, and admin/something are not allowed,
// Trim any surrounding slashes from the alias to
// but something like admin-meeting would be.
// ensure that we are getting exact matches for the
if
(
// predefined alias from above. Some users will add
in_array
(
$alias
,
$urls
)
||
// slashes before and after the alias, so just
preg_match
(
'/^\/+$/'
,
$orig_alias
)
||
// easier to check without slashes.
preg_match
(
'/^admin(?:\/.*)?$/'
,
$alias
)
$alias
=
trim
(
$alias
,
'/'
);
)
{
// Check if the alias exists if yes, sets error.
// We are checking three cases, the first is if
// the alias is in the predefined list. The second
// is if the alias is just /, or just a series of slashes,
// we have to check here because we removed all the
// slashes with the alias variable. The last is to check
// if the alias has any form of strictly admin, so /admin/,
// admin, admin/, and admin/something are not allowed,
// but something like admin-meeting would be.
if
(
in_array
(
$alias
,
$urls
)
||
preg_match
(
'/^\/+$/'
,
$orig_alias
)
||
preg_match
(
'/^admin(?:\/.*)?$/'
,
$alias
)
)
{
// Set an error message if alias exists.
// Set an error message if alias exists.
$form_state
->
setError
(
$form
[
'path'
][
'widget'
][
0
][
'alias'
],
t
(
'The alias "@url" is a reserved path that cannot be used.'
,
[
'@url'
=>
$orig_alias
]));
$form_state
->
setError
(
$form
[
'path'
][
'widget'
][
0
][
'alias'
],
t
(
'The alias "@url" is a reserved path that cannot be used.'
,
[
'@url'
=>
$orig_alias
]));
}
}
}
}
}
...
...
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