Skip to content

Commit

Permalink
VACMS-17515: Hiding service options and appointments on Non-clinical …
Browse files Browse the repository at this point in the history
…services (#18169)

* VACMS-17515: Hiding service options

* VACMS-17515: Refactors working code in va_gov_backend

* VACMS-17515: Moves code to vamc, where it belongs.

* VACMS-17515: Revert inadvertent change.

* VACMS-17515: Update the comment to match the code.

* VACMS-17515: Adds some defensive code, after PR
  • Loading branch information
omahane authored May 22, 2024
1 parent afa6da4 commit ea274ec
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docroot/modules/custom/va_gov_vamc/va_gov_vamc.module
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ function va_gov_vamc_form_alter(&$form, FormStateInterface $form_state, $form_id
_va_gov_vamc_vbo_facility_status_form_ui($form, $form_state);
}
}
if ($form_id === 'node_vha_facility_nonclinical_service_edit_form') {
_va_gov_vamc_remove_service_location_fields_from_non_clinical_services($form);
}
}

/**
Expand Down Expand Up @@ -238,3 +241,42 @@ function va_gov_vamc_entity_bundle_field_info_alter(&$fields, EntityTypeInterfac
}

}

/**
* Removes unnecessary Service location fields from non-clinical services.
*
* @param array $form
* The node form.
*/
function _va_gov_vamc_remove_service_location_fields_from_non_clinical_services(&$form) {
// If the field_service_location is not found, return.
if (!array_key_exists('field_service_location', $form)) {
return;
}
$service_location_widget = array_key_exists('widget', $form['field_service_location'])
? $form['field_service_location']['widget']
: [];
// If the service location widget is not iterable or is empty, return.
if (!is_iterable($service_location_widget) || empty($service_location_widget)) {
return;
}
foreach ($service_location_widget as $key => $widget) {
if (is_numeric($key)) {
// Service options and Appointments are not relevant
// to non-clinical services.
$groups_to_clear = [
'group_service_options',
'group_appointments',
];
foreach ($groups_to_clear as $group) {
if (isset($widget['subform']['#fieldgroups'][$group])) {
// In each group, set the access to false for all child fields,
// so they are not rendered.
foreach ($form['field_service_location']['widget'][$key]['subform']['#fieldgroups'][$group]->children as $form_element_id) {
$form["field_service_location"]["widget"][$key]["subform"][$form_element_id]["#access"] = FALSE;
}
}
}
}
}
}

0 comments on commit ea274ec

Please sign in to comment.