Skip to content

Commit

Permalink
VACMS-19623: Phone label should not show in some forms (#20218)
Browse files Browse the repository at this point in the history
* 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 7e8cad5.

* VACMS-19967: Removes old mental health phone number

* Revert "VACMS-19967: Removes old mental health phone number"

This reverts commit 80bdbe6.

* 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
  • Loading branch information
omahane authored Jan 8, 2025
1 parent ba24a48 commit fd1bd17
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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;

}
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public function entityTypeAlter(EntityTypeAlterEvent $event): void {
*/
public function alterstaffProfileNodeForm(FormIdAlterEvent $event): void {
$this->addStateManagementToBioFields($event);
$this->removePhoneLabel($event);
}

/**
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -359,7 +347,6 @@ public function alterTopTaskNodeForm(FormIdAlterEvent $event): void {
*/
public function alterVamcSystemBillingAndInsuranceForm(FormIdAlterEvent $event) {
$this->alterTopTaskNodeForm($event);
$this->removePhoneLabel($event);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down

0 comments on commit fd1bd17

Please sign in to comment.