From 6f9faeaab74f1648dc06a1102022be8aa84862ec Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 7 Jan 2025 09:26:46 -0600 Subject: [PATCH] VACMS-19623: Further cleanup, hiding label in form, cypress --- .../EventSubscriber/EntityEventSubscriber.php | 48 +++++++++++++++++++ .../VAMCEntityEventSubscriber.php | 12 ----- .../content_type/person_profile.feature | 9 +++- 3 files changed, 56 insertions(+), 13 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_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php b/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php index 35ba15e763..a0692f184f 100644 --- a/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php +++ b/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php @@ -13,7 +13,6 @@ use Drupal\core_event_dispatcher\Event\Entity\EntityUpdateEvent; use Drupal\core_event_dispatcher\Event\Entity\EntityViewAlterEvent; use Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent; -use Drupal\feature_toggle\FeatureStatus; use Drupal\node\NodeInterface; use Drupal\va_gov_notifications\Service\NotificationsManager; use Drupal\va_gov_user\Service\UserPermsService; @@ -106,13 +105,6 @@ public static function getSubscribedEvents(): array { */ protected $userPermsService; - /** - * Feature Toggle status service. - * - * @var \Drupal\feature_toggle\FeatureStatus - */ - private FeatureStatus $featureStatus; - /** * Constructs the EventSubscriber object. * @@ -128,8 +120,6 @@ public static function getSubscribedEvents(): array { * The deduper service. * @param \Drupal\va_gov_notifications\Service\NotificationsManager $notifications_manager * VA gov NotificationsManager service. - * @param \Drupal\feature_toggle\FeatureStatus $feature_status - * The Feature Status service. */ public function __construct( EntityTypeManager $entity_type_manager, @@ -138,7 +128,6 @@ public function __construct( UserPermsService $user_perms_service, ContentHardeningDeduper $content_hardening_deduper, NotificationsManager $notifications_manager, - FeatureStatus $feature_status, ) { $this->entityTypeManager = $entity_type_manager; $this->currentUser = $currentUser; @@ -146,7 +135,6 @@ public function __construct( $this->userPermsService = $user_perms_service; $this->contentHardeningDeduper = $content_hardening_deduper; $this->notificationsManager = $notifications_manager; - $this->featureStatus = $feature_status; } /** 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."