diff --git a/docroot/modules/custom/va_gov_vet_center/src/EventSubscriber/EntityEventSubscriber.php b/docroot/modules/custom/va_gov_vet_center/src/EventSubscriber/EntityEventSubscriber.php index 0b52298924..bf46adca32 100644 --- a/docroot/modules/custom/va_gov_vet_center/src/EventSubscriber/EntityEventSubscriber.php +++ b/docroot/modules/custom/va_gov_vet_center/src/EventSubscriber/EntityEventSubscriber.php @@ -240,7 +240,84 @@ public function alterVetCenterServiceNodeForm(FormIdAlterEvent $event): void { $is_admin = $this->userPermsService->hasAdminRole(TRUE); if (!$is_admin) { $this->disableFacilityServiceChange($form, $form_state); + $this->disableArchivingRequiredServicesNonAdmins($form, $form_state); } + $this->showServiceAsRequiredOrOptional($form, $form_state); + + } + + /** + * Disable the Archived moderation state on required services for non-admins. + * + * @param array $form + * The node form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state. + */ + public function disableArchivingRequiredServicesNonAdmins(array &$form, FormStateInterface $form_state) { + $required_services = $this->requiredServices->getRequiredServices(); + $form_object = $form_state->getFormObject(); + $node = $form_object->getEntity(); + $service_id = $node->field_service_name_and_descripti->target_id; + foreach ($required_services as $required_service) { + $required_service_id = $required_service->id(); + if ($service_id == $required_service_id) { + if ($form['moderation_state']['widget'][0]['state']['#options']['archived']) { + unset($form['moderation_state']['widget'][0]['state']['#options']['archived']); + } + } + } + } + + /** + * Show service as required or optional. + * + * @param array $form + * The node form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state. + */ + public function showServiceAsRequiredOrOptional(array &$form, FormStateInterface $form_state) { + $required_services = $this->requiredServices->getRequiredServices(); + $form_object = $form_state->getFormObject(); + $node = $form_object->getEntity(); + $service_id = $node->field_service_name_and_descripti->target_id; + $service_name = $node->field_service_name_and_descripti->entity->getName(); + foreach ($required_services as $required_service) { + $required_service_id = $required_service->id(); + if ($service_id == $required_service_id) { + // This is a required service. + $service_required_or_optional = $this->t('a required'); + $can_or_cannot = $this->t('cannot'); + $service_required_or_optional_capitalized = $this->t('Required'); + break; + } + else { + // This is an optional service. + $service_required_or_optional = $this->t('an optional'); + $can_or_cannot = $this->t('can'); + $service_required_or_optional_capitalized = $this->t('Optional'); + } + } + + $required_or_optional_markup = new FormattableMarkup( + '
:service_required_or_optional_capitalized Service
+
:service_name is :required_or_optional service. :service_required_or_optional_capitalized services :can_or_cannot be archived. Learn more in the Knowledge Base article about Vet Center Services (opens in a new window).