Skip to content

Commit

Permalink
VACMS-19623: Further cleanup, hiding label in form, cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
omahane committed Jan 7, 2025
1 parent b3260bf commit 6f9faea
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 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 @@ -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;
Expand Down Expand Up @@ -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.
*
Expand All @@ -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,
Expand All @@ -138,15 +128,13 @@ 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;
$this->flagger = $flagger;
$this->userPermsService = $user_perms_service;
$this->contentHardeningDeduper = $content_hardening_deduper;
$this->notificationsManager = $notifications_manager;
$this->featureStatus = $feature_status;
}

/**
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 6f9faea

Please sign in to comment.