From e8604acee8e8190b3d3867a09f49e518ae351aa2 Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Mon, 4 Mar 2024 14:29:48 -0600 Subject: [PATCH 1/3] VACMS-13214: Adds alter to view to alphabetize and remove archived. --- .../VAMCEntityEventSubscriber.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) 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..81ad66fd8c 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,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]; + + } + } } /** From 5f90762f9933e9d0f0e584e613c2757f67a18eb0 Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 5 Mar 2024 09:35:06 -0600 Subject: [PATCH 2/3] VACMS-13214: Updates view to give style to draft --- .../VAMCEntityEventSubscriber.php | 46 ++++++++++++------- .../va_gov_vamc/va_gov_vamc.libraries.yml | 5 +- 2 files changed, 33 insertions(+), 18 deletions(-) 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 81ad66fd8c..f3e94040a1 100644 --- a/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php +++ b/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php @@ -146,44 +146,56 @@ public function __construct( */ public function entityViewAlter(EntityViewAlterEvent $event):void { $this->showUnspecifiedWhenSystemEhrNumberEmpty($event); - $this->appendHealthServiceToVamcSystem($event); + $this->alterAppendedSystemHealthServices($event); + } /** - * Appends health service title on entity view page. + * 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 appendHealthServiceToVamcSystem(EntityViewAlterEvent $event):void { + 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'] ?? []; - // usort($services, '$this->querySort'); - $temp_array = []; + $services_copy = []; foreach ($services as $key => $service) { - // If there are services (because their keys are numeric.) + // 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]; + // Copy build array. + $services_copy[] = $build['field_clinical_health_services'][$key]; unset($build['field_clinical_health_services'][$key]); - $service_node = $temp_array[$key]['#options']['entity']; + $service_node = $services_copy[$key]['#options']['entity']; $moderationState = $service_node->get('moderation_state')->value; + // Remove archived from temp array. if ($moderationState === 'archived') { - unset($temp_array[$key]); + unset($services_copy[$key]); + } + // If draft, show as such on view. + $thisRevisionIsPublished = $service_node->isPublished(); + $defaultRevisionIsPublished = (isset($service_node->original) && ($service_node->original instanceof EntityInterface)) + ? (bool) $service_node->original->status->value + : (bool) $service_node->status->value; + if (!$defaultRevisionIsPublished && !$thisRevisionIsPublished) { + $services_copy[$key]['#attributes'] = ['class' => 'node--unpublished']; } } - - } - 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]; - } + // 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: {} From a12f77dcfe6a9c4d2c67387d9ce642aeedceb780 Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 5 Mar 2024 11:49:28 -0600 Subject: [PATCH 3/3] VACMS-13214: Refactors draft and archived display --- .../css/set_vamc_system_health_service.css | 3 +++ .../EventSubscriber/VAMCEntityEventSubscriber.php | 13 +++---------- 2 files changed, 6 insertions(+), 10 deletions(-) create mode 100644 docroot/modules/custom/va_gov_vamc/css/set_vamc_system_health_service.css 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 f3e94040a1..d1b51c31a9 100644 --- a/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php +++ b/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php @@ -171,17 +171,10 @@ public function alterAppendedSystemHealthServices(EntityViewAlterEvent $event):v unset($build['field_clinical_health_services'][$key]); $service_node = $services_copy[$key]['#options']['entity']; $moderationState = $service_node->get('moderation_state')->value; - // Remove archived from temp array. - if ($moderationState === 'archived') { - unset($services_copy[$key]); - } - // If draft, show as such on view. - $thisRevisionIsPublished = $service_node->isPublished(); - $defaultRevisionIsPublished = (isset($service_node->original) && ($service_node->original instanceof EntityInterface)) - ? (bool) $service_node->original->status->value - : (bool) $service_node->status->value; - if (!$defaultRevisionIsPublished && !$thisRevisionIsPublished) { + // 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) . ')'; } } }