diff --git a/docroot/modules/custom/va_gov_vamc/css/set_vamc_system_health_service.css b/docroot/modules/custom/va_gov_vamc/css/set_vamc_system_health_service.css new file mode 100644 index 0000000000..83c9900f12 --- /dev/null +++ b/docroot/modules/custom/va_gov_vamc/css/set_vamc_system_health_service.css @@ -0,0 +1,3 @@ +.field--name-field-clinical-health-services a.node--unpublished { + padding: unset; + } \ No newline at end of file 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 6be24b9a33..d1b51c31a9 100644 --- a/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php +++ b/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php @@ -146,6 +146,49 @@ public function __construct( */ public function entityViewAlter(EntityViewAlterEvent $event):void { $this->showUnspecifiedWhenSystemEhrNumberEmpty($event); + $this->alterAppendedSystemHealthServices($event); + + } + + /** + * Alters health service titles appended to VAMC system view page. + * + * @param \Drupal\core_event_dispatcher\Event\Entity\EntityViewAlterEvent $event + * The entity view alter service. + */ + public function alterAppendedSystemHealthServices(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'] ?? []; + + $services_copy = []; + foreach ($services as $key => $service) { + // If there are services (because their keys are numeric). + if (is_numeric($key) && !empty($service['#options']['entity'])) { + // Copy build array. + $services_copy[] = $build['field_clinical_health_services'][$key]; + unset($build['field_clinical_health_services'][$key]); + $service_node = $services_copy[$key]['#options']['entity']; + $moderationState = $service_node->get('moderation_state')->value; + // Identify archive and draft in temp array. + if ($moderationState === 'archived' || $moderationState === 'draft') { + $services_copy[$key]['#attributes'] = ['class' => 'node--unpublished']; + $services_copy[$key]['#title'] .= ' (' . ucfirst($moderationState) . ')'; + } + } + } + // Sort temp array. + usort($services_copy, function ($x, $y) { + return strcasecmp($x['#title'], $y['#title']); + }); + // Copy temporary array back to build array. + foreach ($services_copy as $key => $temp) { + $build['field_clinical_health_services'][$key] = $services_copy[$key]; + } + $build['field_clinical_health_services']['#attached']['library'][] = 'va_gov_vamc/set_vamc_system_health_service'; + } + } /** diff --git a/docroot/modules/custom/va_gov_vamc/va_gov_vamc.libraries.yml b/docroot/modules/custom/va_gov_vamc/va_gov_vamc.libraries.yml index 61da43d5dc..1f202a626b 100644 --- a/docroot/modules/custom/va_gov_vamc/va_gov_vamc.libraries.yml +++ b/docroot/modules/custom/va_gov_vamc/va_gov_vamc.libraries.yml @@ -16,4 +16,7 @@ set_covid_term_text: css/set_covid_term_text.css: {} js: js/set_covid_term_text.js: {} - +set_vamc_system_health_service: + css: + component: + css/set_vamc_system_health_service.css: {}