From 723ccde8b0bed2b718e5267104b8dd48fff95ac5 Mon Sep 17 00:00:00 2001 From: Steve Wirt Date: Fri, 9 Feb 2024 15:25:31 -0500 Subject: [PATCH] VACMS-16233 Add reorder VAMC System menu items. --- .../VACMS-16233-reorder-vamc-menu-items.php | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 scripts/content/VACMS-16233-reorder-vamc-menu-items.php diff --git a/scripts/content/VACMS-16233-reorder-vamc-menu-items.php b/scripts/content/VACMS-16233-reorder-vamc-menu-items.php new file mode 100644 index 0000000000..41123b2247 --- /dev/null +++ b/scripts/content/VACMS-16233-reorder-vamc-menu-items.php @@ -0,0 +1,99 @@ + 0]; + do { + print(va_gov_vamc_deploy_resort_vamc_menus($sandbox)); + } while ($sandbox['#finished'] < 1); + + return "Script run complete. All menus should have been updated. "; +} + +/** + * Re-sort VAMC menus. + * + * @param mixed $sandbox + * Batch sandbox to keep state during multiple runs. + * + * @return string + * The message to be output. + */ +function va_gov_vamc_deploy_resort_vamc_menus(&$sandbox) { + script_library_sandbox_init($sandbox, '_va_gov_vamc_get_system_menus', []); + _va_gov_vamc_arrange_menus($sandbox); + return script_library_sandbox_complete($sandbox, "Re-arranged @total VAMC System Menus."); +} + +/** + * Get all VAMC system menus. + * + * @return array + * An array of VAMC system menus ['machine_name' => 'Human Name']. + */ +function _va_gov_vamc_get_system_menus(): array { + // Load the menus. + $vamc_menus = MenuManipulator::getAllMenuNames('-health-'); + $non_name_compliant_menus = [ + 'va-central-western-massachusetts' => 'VA Central Western Massachusetts health care', + 'va-columbia-south-carolina-healt' => 'VA Columbia South Carolina health care', + 'va-lebanon' => 'VA Lebanon health care', + ]; + + return array_merge($vamc_menus, $non_name_compliant_menus); +} + +/** + * Re-arranges existing VAMC menus to match a pattern. + * + * @param mixed $sandbox + * Batch sandbox to keep state during multiple runs. + * + * @return string + * A message to be output. + */ +function _va_gov_vamc_arrange_menus(&$sandbox) { + $menu_name = array_key_first($sandbox['items_to_process']); + $pattern = [ + 'About us', + 'Programs', + 'Research', + 'Policies', + 'VA police', + 'Work with us', + 'Contact us', + ]; + $menu_arranger = new MenuManipulator($menu_name); + $menu_arranger->matchPattern($pattern); + $message = "The menu {$sandbox['items_to_process'][$menu_name]} had been rearranged."; + unset($sandbox['items_to_process'][$menu_name]); + $sandbox['current']++; + + return $message; +}