From 6a48ce9559d63ea979b2dde93769fb184597aaec Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Thu, 4 Jan 2024 16:40:19 -0600 Subject: [PATCH] VACMS-15901: Removes facilities not in user's sections --- .../custom/va_gov_backend/va_gov_backend.module | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docroot/modules/custom/va_gov_backend/va_gov_backend.module b/docroot/modules/custom/va_gov_backend/va_gov_backend.module index 59838623745..c6a4af772ea 100644 --- a/docroot/modules/custom/va_gov_backend/va_gov_backend.module +++ b/docroot/modules/custom/va_gov_backend/va_gov_backend.module @@ -419,12 +419,12 @@ function va_gov_backend_form_alter(&$form, FormStateInterface $form_state, $form // Only run when on a node. // Additionally, reduce the number of times called when editing a paragraph, // which will have a triggering_element set. - if (isset($form['#entity_type']) - && $form['#entity_type'] === 'node' - && (!$form_state->getTriggeringElement())) { + $base_form_id = $form_state->getBuildInfo()['base_form_id'] ?? ''; + if ((!$form_state->getTriggeringElement()) && ($base_form_id === "node_form")) { $targets = [ 'field_office', 'field_listing', + 'field_facility_location', ]; _va_gov_backend_dropdown_field_access($form, $targets); } @@ -1045,6 +1045,13 @@ function _va_gov_backend_dropdown_field_access(array &$form, array $targets) { } } } + elseif (!empty($option_header)) { + // If not an array, it's just an option. + // If not in the allowed items array, take it out. + if (!in_array($header_key, $allowed_options)) { + unset($form[$target]['widget']['#options'][$header_key]); + } + } } } }