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
91482c5c
Commit
91482c5c
authored
2 years ago
by
Eric Bremner
Committed by
Kevin Paxman
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5880: adding the custom validation for banners
parent
8b0d3e58
No related branches found
Branches containing commit
No related tags found
Tags containing commit
3 merge requests
!284
Feature/istwcms 5880 ebremner banners above
,
!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
+67
-1
67 additions, 1 deletion
uw_cfg_common.module
with
67 additions
and
1 deletion
uw_cfg_common.module
+
67
−
1
View file @
91482c5c
...
@@ -928,7 +928,7 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
...
@@ -928,7 +928,7 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
],
],
];
];
// Set the states for the banner.
// Set the states for the banner
settings
.
$form
[
'group_banner_settings'
][
'#states'
]
=
[
$form
[
'group_banner_settings'
][
'#states'
]
=
[
'visible'
=>
[
'visible'
=>
[
[
[
...
@@ -938,6 +938,9 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
...
@@ -938,6 +938,9 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
],
],
],
],
];
];
// Add our custom validation for banners.
$form
[
'#validate'
][]
=
'_uw_cfg_common_banner_validate'
;
}
}
// If we are on the media upload form, we want to restrict
// If we are on the media upload form, we want to restrict
...
@@ -1040,6 +1043,69 @@ function _uw_cfg_common_alias_validate(array &$form, FormStateInterface $form_st
...
@@ -1040,6 +1043,69 @@ function _uw_cfg_common_alias_validate(array &$form, FormStateInterface $form_st
}
}
}
}
/**
* Validates submission values for banners on nodes.
*/
function
_uw_cfg_common_banner_validate
(
array
&
$form
,
FormStateInterface
$form_state
)
{
// Get the values of the form state.
$values
=
$form_state
->
getValues
();
// If there is a type of media set and it is banners,
// then perform the validation.
if
(
isset
(
$values
[
'field_uw_type_of_media'
])
&&
$values
[
'field_uw_type_of_media'
][
0
][
'value'
]
==
'banner'
)
{
// Since the add more button is in the values, and there is
// a mix of integers and strings as keys, we need to count
// the array keys and if it is less than or equal to one
// means that the user has not entered a banner at all.
if
(
count
(
array_keys
(
$values
[
'field_uw_banner'
]))
<=
1
)
{
$form_state
->
setError
(
$form
[
'field_uw_banner'
],
t
(
'You must add at least one banner.'
));
}
// At least one banner, now check that there is an
// image in each banner.
else
{
// Step through all the values of banners and check for an image.
foreach
(
$values
[
'field_uw_banner'
]
as
$key
=>
$value
)
{
// Ensure that the key is an integer, since there is an add_more
// in the values.
if
(
is_int
(
$key
))
{
// If there is no selection on the media, then there is no image,
// so set the error.
// @TO-DO: fix so that inline errors show.
if
(
!
isset
(
$value
[
'subform'
][
'field_uw_ban_image'
][
'selection'
]))
{
// Set the error that an image is missing.
$form_state
->
setError
(
$form
[
'field_uw_banner'
][
'widget'
][
$key
][
'subform'
][
'field_uw_ban_image'
],
t
(
'Banner image field is required.'
));
}
}
}
}
}
}
/**
* Implements hook_field_widget_WIDGET_TYPE_form_alter().
*/
function
uw_cfg_common_field_widget_entity_reference_paragraphs_form_alter
(
&
$element
,
&
$form_state
,
$context
)
{
if
(
$element
[
'#paragraph_type'
]
==
'uw_para_image_banner'
)
{
if
(
!
isset
(
$context
[
'form'
][
'#block'
]))
{
$element
[
'subform'
][
'field_uw_ban_image'
][
'widget'
][
'#attributes'
][
'class'
]
=
'form-required js-form-required'
;
}
else
{
$element
[
'subform'
][
'field_uw_ban_image'
][
'widget'
][
'#required'
]
=
TRUE
;
}
}
}
/**
/**
* Implements hook_field_widget_WIDGET_TYPE_form_alter().
* Implements hook_field_widget_WIDGET_TYPE_form_alter().
*/
*/
...
...
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