From fd1bd1728f96900dcbc9213664da06b39fd03384 Mon Sep 17 00:00:00 2001 From: Christian Burk <766573+omahane@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:14:29 -0600 Subject: [PATCH] VACMS-19623: Phone label should not show in some forms (#20218) * VACMS-19967: Removes toggle configuration and dependent code * VACMS-19967: Removal of the rest of the code, one hopes * VACMS-19967: Removes constructor, as no longer overridden * VACMS-19967: Removes telephone field from config * Revert "VACMS-19967: Removes telephone field from config" This reverts commit 7e8cad56a940d9a0a587c86260e4b0730f528623. * VACMS-19967: Removes old mental health phone number * Revert "VACMS-19967: Removes old mental health phone number" This reverts commit 80bdbe6dc6b8272c1dcde41f7f2e824e647d1eb2. * VACMS-19967: Updates view to remove old number * VACMS-19667: Removes old phone from staff profile * VACMS-19967: Removes old phone from billing * VACMS-19623: Removes the phone label from appropriate bundles * VACMS-19967: Updates the view and removes the old mental health * VACMS-19623: Further cleanup, hiding label in form, cypress * VACMS-19623: Removes old code for label removal from profile * VACMS-19623: Removes old code that snuck in --- .../EventSubscriber/EntityEventSubscriber.php | 48 +++++++++++++++++++ .../EventSubscriber/EntityEventSubscriber.php | 12 ----- .../VAMCEntityEventSubscriber.php | 13 ----- .../content_type/person_profile.feature | 9 +++- 4 files changed, 56 insertions(+), 26 deletions(-) diff --git a/docroot/modules/custom/va_gov_backend/src/EventSubscriber/EntityEventSubscriber.php b/docroot/modules/custom/va_gov_backend/src/EventSubscriber/EntityEventSubscriber.php index 55f268fcfd..816b4deebd 100644 --- a/docroot/modules/custom/va_gov_backend/src/EventSubscriber/EntityEventSubscriber.php +++ b/docroot/modules/custom/va_gov_backend/src/EventSubscriber/EntityEventSubscriber.php @@ -4,6 +4,7 @@ use Drupal\Core\Config\Entity\ConfigEntityType; use Drupal\Core\Entity\EntityTypeManager; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\core_event_dispatcher\EntityHookEvents; use Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent; @@ -239,6 +240,8 @@ public function lockCentralizedContentFields(array &$form) { public function formWidgetAlter(WidgetSingleElementFormAlterEvent $event): void { $form = &$event->getElement(); $this->removeCollapseButton($form); + $form_state = $event->getFormState(); + $this->removePhoneLabel($form, $form_state); } /** @@ -253,4 +256,49 @@ public function removeCollapseButton(array &$form) { } } + /** + * Removes the phone label from certain forms. + * + * @param array $form + * The form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form_state. + */ + public function removePhoneLabel(array &$form, FormStateInterface $form_state): void { + if (!empty($form['#field_parents']) && in_array('field_telephone', $form['#field_parents'])) { + + if ($form['#title'] === 'Label') { + $form_id = $form_state->getFormObject()->getFormId(); + + // The forms that should not have phone labels. + $forms_without_phone_labels = [ + 'node_person_profile_form', + 'node_person_profile_edit_form', + 'node_health_care_local_facility_form', + 'node_health_care_local_facility_edit_form', + 'node_vamc_system_billing_insurance_form', + 'node_vamc_system_billing_insurance_edit_form', + ]; + + if (in_array($form_id, $forms_without_phone_labels)) { + // Hide the field on the form. + $form['#access'] = FALSE; + // Set the default value to 'Label' to satisfy the required field. + // Otherwise, it will throw an validation error. + switch ($form_id) { + case 'node_health_care_local_facility_form': + case 'node_health_care_local_facility_edit_form': + $form['value']['#default_value'] = 'Mental health phone'; + break; + + default: + $form['value']['#default_value'] = 'Phone'; + break; + + } + } + } + } + } + } diff --git a/docroot/modules/custom/va_gov_profile/src/EventSubscriber/EntityEventSubscriber.php b/docroot/modules/custom/va_gov_profile/src/EventSubscriber/EntityEventSubscriber.php index 1154f86511..f197665626 100644 --- a/docroot/modules/custom/va_gov_profile/src/EventSubscriber/EntityEventSubscriber.php +++ b/docroot/modules/custom/va_gov_profile/src/EventSubscriber/EntityEventSubscriber.php @@ -80,7 +80,6 @@ public function entityTypeAlter(EntityTypeAlterEvent $event): void { */ public function alterstaffProfileNodeForm(FormIdAlterEvent $event): void { $this->addStateManagementToBioFields($event); - $this->removePhoneLabel($event); } /** @@ -131,15 +130,4 @@ public function addStateManagementToBioFields(FormIdAlterEvent $event) { ]; } - /** - * Removes the phone label on staff profile content type forms. - * - * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event - * The form event. - */ - private function removePhoneLabel(FormIdAlterEvent $event): void { - $form = &$event->getForm(); - $form['field_telephone']['widget'][0]['subform']['field_phone_label']['#access'] = FALSE; - } - } diff --git a/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php b/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php index a0692f184f..ad1985bd85 100644 --- a/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php +++ b/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php @@ -304,17 +304,6 @@ public function addCovidStatusData(array &$form, FormStateInterface $form_state) } } - /** - * Removes the phone label on VAMC facility content type forms. - * - * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event - * The event. - */ - private function removePhoneLabel(FormIdAlterEvent $event): void { - $form = &$event->getForm(); - $form['field_telephone']['widget'][0]['subform']['field_phone_label']['#access'] = FALSE; - } - /** * Alter VAMC Facility node form. * @@ -325,7 +314,6 @@ public function alterFacilityNodeForm(FormIdAlterEvent $event): void { $form = &$event->getForm(); $form_state = $event->getFormState(); $this->addCovidStatusData($form, $form_state); - $this->removePhoneLabel($event); } /** @@ -359,7 +347,6 @@ public function alterTopTaskNodeForm(FormIdAlterEvent $event): void { */ public function alterVamcSystemBillingAndInsuranceForm(FormIdAlterEvent $event) { $this->alterTopTaskNodeForm($event); - $this->removePhoneLabel($event); } /** diff --git a/tests/cypress/integration/features/content_type/person_profile.feature b/tests/cypress/integration/features/content_type/person_profile.feature index fbab9a7b29..6b84e78415 100644 --- a/tests/cypress/integration/features/content_type/person_profile.feature +++ b/tests/cypress/integration/features/content_type/person_profile.feature @@ -14,8 +14,15 @@ Scenario: Log in and create a Person Profile with attention to conditional field And I fill in "Last name" with "Smith" And I click the "Add Phone number" button And I wait "5" seconds - And I fill in field with selector "[data-drupal-selector='edit-field-telephone-0-subform-field-phone-number-0-value']" with value "402-867-5309" + And I fill in field with selector "[data-drupal-selector*='subform-field-phone-number-0-value']" with value "402-867-5309" And I fill in field with selector "#edit-revision-log-0-value" with value "[Test Data] Revision log message." + And I click the "Remove" button + And I wait "5" seconds + And I click the "Confirm removal" button + And I wait "5" seconds + And I click the "Add Phone number" button + And I wait "5" seconds + And I fill in field with selector "[data-drupal-selector*='subform-field-phone-number-0-value']" with value "402-867-5309" And I click the "Save" button Then I should see "Staff Profile James Smith has been created."