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
aeb32fa6
Commit
aeb32fa6
authored
2 years ago
by
Eric Bremner
Committed by
Kevin Paxman
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5846: adding fake required for blank summaries and drupal validation for the summary
parent
bdc9f190
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!295
ISTWCMS-5846: adding code and config for blank summaries
,
!274
Draft: ISTWCMS-5551: fixing office hours display
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uw_cfg_common.module
+77
-3
77 additions, 3 deletions
uw_cfg_common.module
with
77 additions
and
3 deletions
uw_cfg_common.module
+
77
−
3
View file @
aeb32fa6
...
@@ -38,6 +38,48 @@ function uw_cfg_common_preprocess_form_element(&$variables) {
...
@@ -38,6 +38,48 @@ function uw_cfg_common_preprocess_form_element(&$variables) {
}
}
}
}
/**
* Implements template_preprocess_form_element_label().
*/
function
uw_cfg_common_preprocess_form_element_label
(
&
$variables
)
{
// Check if we need to add the form required to the label.
// Conditions are not the blank summary checkbox,
// the id of the label contains edit-field-uw and has
// either summary or position in the id.
if
(
$variables
[
'element'
][
'#id'
]
!==
'edit-field-uw-blank-summary-value'
&&
str_contains
(
$variables
[
'element'
][
'#id'
],
'edit-field-uw-'
)
&&
(
str_contains
(
$variables
[
'element'
][
'#id'
],
'summary'
)
||
str_contains
(
$variables
[
'element'
][
'#id'
],
'position'
)
)
)
{
// Try and get the node type, by replacing the id of the label.
$node_type
=
$variables
[
'element'
][
'#id'
];
$node_type
=
str_replace
(
'edit-field-uw-'
,
''
,
$node_type
);
$node_type
=
str_replace
(
'-summary-0-value'
,
''
,
$node_type
);
$node_type
=
str_replace
(
'-position-0-value'
,
''
,
$node_type
);
// The node types to place the form required on the label.
$blank_summary_node_types
=
[
'blog'
,
'event'
,
'news'
,
'opportunity'
,
'profile'
,
'project'
,
];
// If we are on a node that needs a form required
// on the label add the class.
if
(
in_array
(
$node_type
,
$blank_summary_node_types
))
{
$variables
[
'attributes'
][
'class'
][]
=
'form-required'
;
}
}
}
/**
/**
* Implements hook_sendgrid_integration_categories_alter().
* Implements hook_sendgrid_integration_categories_alter().
*
*
...
@@ -955,13 +997,13 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
...
@@ -955,13 +997,13 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
// Set the states of the summary, required and visible.
// Set the states of the summary, required and visible.
$form
[
$field_name
][
'widget'
][
0
][
'#states'
]
=
[
$form
[
$field_name
][
'widget'
][
0
][
'#states'
]
=
[
'required'
=>
[
':input[name="field_uw_blank_summary[value]"]'
=>
[
'checked'
=>
FALSE
],
],
'visible'
=>
[
'visible'
=>
[
':input[name="field_uw_blank_summary[value]"]'
=>
[
'checked'
=>
FALSE
],
':input[name="field_uw_blank_summary[value]"]'
=>
[
'checked'
=>
FALSE
],
],
],
];
];
// Add custom validation for blank summaries.
$form
[
'#validate'
][]
=
'_uw_cfg_common_blank_summaries_validation'
;
}
}
}
}
...
@@ -1163,6 +1205,38 @@ function _uw_cfg_common_alias_validate(array &$form, FormStateInterface $form_st
...
@@ -1163,6 +1205,38 @@ function _uw_cfg_common_alias_validate(array &$form, FormStateInterface $form_st
}
}
}
}
/**
* Validates submission values for banners on nodes.
*/
function
_uw_cfg_common_blank_summaries_validation
(
array
&
$form
,
FormStateInterface
$form_state
)
{
// Get the values from the form state.
$values
=
$form_state
->
getValues
();
// Get the node type.
$node_type
=
str_replace
(
'node_uw_ct_'
,
''
,
$form
[
'#form_id'
]);
$node_type
=
str_replace
(
'_edit'
,
''
,
$node_type
);
$node_type
=
str_replace
(
'_form'
,
''
,
$node_type
);
$node_type
=
str_replace
(
'_item'
,
''
,
$node_type
);
// If the node type is an opportunity, we have to give
// the specific field name, if not just use the field name.
if
(
$node_type
==
'opportunity'
)
{
$field_name
=
'field_uw_opportunity_position'
;
}
else
{
$field_name
=
'field_uw_'
.
$node_type
.
'_summary'
;
}
// If the blank summary is checked and the summary is null,
// then set an error.
if
(
!
$values
[
'field_uw_blank_summary'
][
'value'
])
{
if
(
$values
[
$field_name
][
0
][
'value'
]
==
''
)
{
$form_state
->
setError
(
$form
[
$field_name
][
'widget'
][
0
],
t
(
'Summary/position field is required.'
));
}
}
}
/**
/**
* Validates submission values for banners on nodes.
* Validates submission values for banners on nodes.
*/
*/
...
...
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