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).

+
', + [ + ':service_required_or_optional_capitalized' => $service_required_or_optional_capitalized, + ':required_or_optional' => $service_required_or_optional, + ':service_name' => $service_name, + ':can_or_cannot' => $can_or_cannot, + ] + ); + $form['service_optional_or_required'] = [ + '#type' => 'markup', + '#markup' => $this->t('@markup', ['@markup' => $required_or_optional_markup]), + '#weight' => 5, + ]; + } /** diff --git a/tests/cypress/integration/features/content_type/facilities/vet_center/vet_center_facility_service.feature b/tests/cypress/integration/features/content_type/facilities/vet_center/vet_center_facility_service.feature index 9f2c81dec2..86bb5995af 100644 --- a/tests/cypress/integration/features/content_type/facilities/vet_center/vet_center_facility_service.feature +++ b/tests/cypress/integration/features/content_type/facilities/vet_center/vet_center_facility_service.feature @@ -15,6 +15,40 @@ Scenario: Editors should not be able to rename a Vet Center - Facility Service And I click the "Unlock" link And I click the "Confirm break lock" button +Scenario: Editors should be able to archive an optional Vet Center - Facility Service + Given I am logged in as a user with the roles "content_creator_vet_center, content_publisher, content_editor" + # Escanaba Vet Center + And my workbench access sections are set to "392" + # Escanaba Vet Center - Workshops and Classes + When I am at "node/19570/edit" + And I scroll to element "select#edit-moderation-state-0-state" + Then an option with the text "Archived" from dropdown with selector "select#edit-moderation-state-0-state" should be visible + Then I scroll to position "bottom" + And I click the "Unlock" link + And I click the "Confirm break lock" button + +Scenario: Editors should be not able to archive a required Vet Center - Facility Service + Given I am logged in as a user with the roles "content_creator_vet_center, content_publisher, content_editor" + # Escanaba Vet Center + And my workbench access sections are set to "392" + # Escanaba Vet Center - Addiction + When I am at "node/17597/edit" + And I scroll to element "select#edit-moderation-state-0-state" + Then an option with the text "Archived" from dropdown with selector "select#edit-moderation-state-0-state" should not be visible + Then I scroll to position "bottom" + And I click the "Unlock" link + And I click the "Confirm break lock" button + +Scenario: Admins should be able to archive a required Vet Center - Facility Service + Given I am logged in as a user with the "administrator" role + # Escanaba Vet Center - Suicide prevention + When I am at "node/17926/edit" + And I scroll to element "select#edit-moderation-state-0-state" + Then an option with the text "Archived" from dropdown with selector "select#edit-moderation-state-0-state" should be visible + Then I scroll to position "bottom" + And I click the "Unlock" link + And I click the "Confirm break lock" button + Scenario: Administrators should be able to rename a Vet Center - Facility Service Given I am logged in as a user with the "administrator" role # Escanaba Vet Center - Telehealth