Skip to content

Commit

Permalink
SG-2143 - check for empty array before iterating (#1683)
Browse files Browse the repository at this point in the history
* SG-2143 - check for empty array before iterating

* SG-2143 - more empty checks
  • Loading branch information
aekong authored May 31, 2024
1 parent 8517c6f commit c6ee9f9
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions web/modules/custom/sfgov_departments/sfgov_departments.module
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ function _sfgov_departments_validate(&$form, FormStateInterface $form_state) {
// TODO: remove this check after existing public bodies have been migrated to department/agency content type
// $form['field_public_body_meetings']['widget']['#cardinality'] = 2; // this property assignment effectively prevents adding more things to know past 2, but there is no feedback regarding the restriction
$thingCount = 0;
foreach ($meetingThingToKnow as $meetingThing) {
if (is_array($meetingThing)) {
if (!empty($meetingThing['subform'])) {
$thingCount++;
if (!empty($meetingThingToKnow)) {
foreach ($meetingThingToKnow as $meetingThing) {
if (is_array($meetingThing)) {
if (!empty($meetingThing['subform'])) {
$thingCount++;
}
}
}
}
Expand Down Expand Up @@ -302,22 +304,26 @@ function _sfgov_departments_dept_req_public_records_form_validate($form, FormSta
*/
function _sfgov_departments_agency_sections_alter_submit(&$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
if (array_key_exists(0, $values['field_agency_sections'])) {
$label = $values['field_agency_sections'][0]['subform']['field_section_title_list'];

// If the section title is set to "None"
if (empty($label) || $label[0]['value'] == '_none') {

foreach ($values['field_agency_sections'][0]['subform']['field_agencies'] as $id => $item) {
// Remove each agency from the agency section.
if (is_numeric($id)) {
unset($values['field_agency_sections'][0]['subform']['field_agencies'][$id]);
if (!empty($values)) {
if (!empty($values['field_agency_sections'])) {
if (array_key_exists(0, $values['field_agency_sections'])) {
$label = $values['field_agency_sections'][0]['subform']['field_section_title_list'];

// If the section title is set to "None"
if (empty($label) || $label[0]['value'] == '_none') {

foreach ($values['field_agency_sections'][0]['subform']['field_agencies'] as $id => $item) {
// Remove each agency from the agency section.
if (is_numeric($id)) {
unset($values['field_agency_sections'][0]['subform']['field_agencies'][$id]);
}
}
}

// Reset the form values with the removed agencies.
$form_state->setValues($values);
}
}

// Reset the form values with the removed agencies.
$form_state->setValues($values);
}
}

Expand Down

1 comment on commit c6ee9f9

@aekong
Copy link
Collaborator Author

@aekong aekong commented on c6ee9f9 May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visit Site

Created multidev environment ci-20255 for sfgov.

Please sign in to comment.