Skip to content

Commit

Permalink
VACMS-13214: Adds alter to view to alphabetize and remove archived.
Browse files Browse the repository at this point in the history
  • Loading branch information
omahane committed Mar 4, 2024
1 parent acfa2a5 commit 6f60001
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,44 @@ public function __construct(
*/
public function entityViewAlter(EntityViewAlterEvent $event):void {
$this->showUnspecifiedWhenSystemEhrNumberEmpty($event);
$this->appendHealthServiceToVamcSystem($event);
}

/**
* Appends health service title on entity view page.
*
* @param \Drupal\core_event_dispatcher\Event\Entity\EntityViewAlterEvent $event
* The entity view alter service.
*/
public function appendHealthServiceToVamcSystem(EntityViewAlterEvent $event):void {
$display = $event->getDisplay();
if (($display->getTargetBundle() === 'health_care_region_page') && ($display->getOriginalMode() === 'full')) {
$build = &$event->getBuild();
$services = $build['field_clinical_health_services'] ?? [];

// usort($services, '$this->querySort');
$temp_array = [];
foreach ($services as $key => $service) {
// If there are services (because their keys are numeric.)
if (is_numeric($key) && !empty($service['#options']['entity'])) {
$temp_array[] = $build['field_clinical_health_services'][$key];
unset($build['field_clinical_health_services'][$key]);
$service_node = $temp_array[$key]['#options']['entity'];
$moderationState = $service_node->get('moderation_state')->value;
if ($moderationState === 'archived') {
unset($temp_array[$key]);
}
}

}
usort($temp_array, function($x, $y) {
return strcasecmp($x['#title'] , $y['#title']);
});
foreach ($temp_array as $key => $temp) {
$build['field_clinical_health_services'][$key] = $temp_array[$key];

}
}
}

/**
Expand Down

0 comments on commit 6f60001

Please sign in to comment.