From 6be77cc4a0d14c2c3d00d93752542fb1fb7755fc Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 2 Jul 2024 09:45:32 -0500 Subject: [PATCH 01/13] VACMS-17885: Entity prepopulate config set --- ..._facility_service.field_administration.yml | 5 ++- ...node.vba_facility_service.field_office.yml | 5 ++- .../EventSubscriber/VbaFacilitySubscriber.php | 40 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/config/sync/field.field.node.vba_facility_service.field_administration.yml b/config/sync/field.field.node.vba_facility_service.field_administration.yml index 5e510bce4a..dc83c47d1a 100644 --- a/config/sync/field.field.node.vba_facility_service.field_administration.yml +++ b/config/sync/field.field.node.vba_facility_service.field_administration.yml @@ -9,14 +9,17 @@ dependencies: module: - entity_reference_validators - epp + - tmgmt_content third_party_settings: entity_reference_validators: circular_reference: false circular_reference_deep: false duplicate_reference: true epp: - value: '' + value: '[current-page:query:field_administration]' on_update: 0 + tmgmt_content: + excluded: false id: node.vba_facility_service.field_administration field_name: field_administration entity_type: node diff --git a/config/sync/field.field.node.vba_facility_service.field_office.yml b/config/sync/field.field.node.vba_facility_service.field_office.yml index bad74f3b24..301ea85a82 100644 --- a/config/sync/field.field.node.vba_facility_service.field_office.yml +++ b/config/sync/field.field.node.vba_facility_service.field_office.yml @@ -9,14 +9,17 @@ dependencies: module: - entity_reference_validators - epp + - tmgmt_content third_party_settings: entity_reference_validators: circular_reference: false circular_reference_deep: false duplicate_reference: false epp: - value: '' + value: '[current-page:query:field_office]' on_update: 0 + tmgmt_content: + excluded: false id: node.vba_facility_service.field_office field_name: field_office entity_type: node diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index ace35421b7..cc0b325d5d 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -11,6 +11,7 @@ use Drupal\core_event_dispatcher\EntityHookEvents; use Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent; use Drupal\core_event_dispatcher\Event\Entity\EntityTypeAlterEvent; +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\node\NodeInterface; @@ -81,9 +82,26 @@ public static function getSubscribedEvents(): array { 'hook_event_dispatcher.form_node_vba_facility_form.alter' => 'alterVbaFacilityNodeForm', EntityHookEvents::ENTITY_TYPE_ALTER => 'entityTypeAlter', EntityHookEvents::ENTITY_PRE_SAVE => 'entityPresave', + EntityHookEvents::ENTITY_UPDATE => 'entityUpdate', + ]; } + /** + * Entity update Event call. + * + * @param \Drupal\core_event_dispatcher\Event\Entity\EntityUpdateEvent $event + * The event. + */ + public function entityUpdate(EntityUpdateEvent $event): void { + $form = &$event->getForm(); + if (!isset($form["#fieldgroups"]["group_facility_services"])) { + return; + } + + $entity = $event->getEntity(); + } + /** * Alteration to entity view pages. * @@ -138,6 +156,28 @@ public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void { $this->changeDismissibleOption($event); } + /** + * Change the link to add a service. + * + * @param \Drupal\core_event_dispatcher\Event\Entity\EntityUpdateEvent $event + * The event. + */ + protected function changeLinkToAddService(EntityUpdateEvent $event): void { + $form = &$event->getForm(); + if (!isset($form["#fieldgroups"]["group_facility_services"])) { + return; + } + $entity = $event->getEntity(); + $form_state = $event->getFormState(); + $term_storage = $this->entityTypeManager->getStorage('taxonomy_term'); + + $facility_section = + $form["#fieldgroups"]["group_facility_services"]->format_settings["description"]->format_settings["description"]; + if (isset($form['group_facility_services']['widget'])) { + $form['field_service_name_and_descripti']['widget']['actions']['add']['#title'] = $this->t('Add a new service'); + } + } + /** * Add states management to banner fields, based on bool. * From 4144a0d4ea2ed88d1997b835f8f815f1f0e41eb5 Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 2 Jul 2024 11:48:32 -0500 Subject: [PATCH 02/13] VACMS-17885: Population of the link is working --- .../EventSubscriber/VbaFacilitySubscriber.php | 39 ++++++------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index cc0b325d5d..b24720c5e2 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -11,7 +11,6 @@ use Drupal\core_event_dispatcher\EntityHookEvents; use Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent; use Drupal\core_event_dispatcher\Event\Entity\EntityTypeAlterEvent; -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\node\NodeInterface; @@ -82,26 +81,9 @@ public static function getSubscribedEvents(): array { 'hook_event_dispatcher.form_node_vba_facility_form.alter' => 'alterVbaFacilityNodeForm', EntityHookEvents::ENTITY_TYPE_ALTER => 'entityTypeAlter', EntityHookEvents::ENTITY_PRE_SAVE => 'entityPresave', - EntityHookEvents::ENTITY_UPDATE => 'entityUpdate', - ]; } - /** - * Entity update Event call. - * - * @param \Drupal\core_event_dispatcher\Event\Entity\EntityUpdateEvent $event - * The event. - */ - public function entityUpdate(EntityUpdateEvent $event): void { - $form = &$event->getForm(); - if (!isset($form["#fieldgroups"]["group_facility_services"])) { - return; - } - - $entity = $event->getEntity(); - } - /** * Alteration to entity view pages. * @@ -154,28 +136,29 @@ public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void { $this->addStateManagementToBannerFields($event); $this->changeBannerType($event); $this->changeDismissibleOption($event); + $this->changeLinkNewService($event); } /** - * Change the link to add a service. + * Changes the link for adding a new VBA Facility service. * - * @param \Drupal\core_event_dispatcher\Event\Entity\EntityUpdateEvent $event + * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - protected function changeLinkToAddService(EntityUpdateEvent $event): void { + protected function changeLinkNewService(FormIdAlterEvent $event): void { $form = &$event->getForm(); if (!isset($form["#fieldgroups"]["group_facility_services"])) { return; } - $entity = $event->getEntity(); $form_state = $event->getFormState(); - $term_storage = $this->entityTypeManager->getStorage('taxonomy_term'); + /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */ + $form_object = $form_state->getFormObject(); + $entity = $form_object->getEntity(); - $facility_section = - $form["#fieldgroups"]["group_facility_services"]->format_settings["description"]->format_settings["description"]; - if (isset($form['group_facility_services']['widget'])) { - $form['field_service_name_and_descripti']['widget']['actions']['add']['#title'] = $this->t('Add a new service'); - } + $section_tid = $entity->field_administration->target_id; + $facility_nid = $entity->nid->value; + $link_url = '/node/add/vba_facility_service?field_administration=' . $section_tid . '&field_office=' . $facility_nid; + $form["#fieldgroups"]["group_facility_services"]->format_settings["description"] = "To create a facility service Add another service"; } /** From 4084b4f57354aecd45823c76eaa543792c7828c0 Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 2 Jul 2024 11:56:31 -0500 Subject: [PATCH 03/13] VACMS-17885: Updates comments --- .../src/EventSubscriber/VbaFacilitySubscriber.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index b24720c5e2..69b088c748 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -142,6 +142,8 @@ public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void { /** * Changes the link for adding a new VBA Facility service. * + * This prepopulates the section and facility for editorial convenience. + * * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ From a314d46ce5cc0079913566afac3971d614659013 Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 2 Jul 2024 12:05:18 -0500 Subject: [PATCH 04/13] VACMS-17885: Adds another null check --- .../src/EventSubscriber/VbaFacilitySubscriber.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index 69b088c748..f561d142ee 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -160,7 +160,9 @@ protected function changeLinkNewService(FormIdAlterEvent $event): void { $section_tid = $entity->field_administration->target_id; $facility_nid = $entity->nid->value; $link_url = '/node/add/vba_facility_service?field_administration=' . $section_tid . '&field_office=' . $facility_nid; - $form["#fieldgroups"]["group_facility_services"]->format_settings["description"] = "To create a facility service Add another service"; + if (isset($form["#fieldgroups"]["group_facility_services"]->format_settings["description"])) { + $form["#fieldgroups"]["group_facility_services"]->format_settings["description"] = "To create a facility service Add another service"; + } } /** From fad64af50f982b979b114679ab8e01face7bd73a Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 2 Jul 2024 12:14:27 -0500 Subject: [PATCH 05/13] VACMS-17885: Updates config --- .../core.entity_form_display.node.vba_facility.default.yml | 7 ++++--- .../src/EventSubscriber/VbaFacilitySubscriber.php | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/sync/core.entity_form_display.node.vba_facility.default.yml b/config/sync/core.entity_form_display.node.vba_facility.default.yml index a4f2a334ed..d73514596f 100644 --- a/config/sync/core.entity_form_display.node.vba_facility.default.yml +++ b/config/sync/core.entity_form_display.node.vba_facility.default.yml @@ -20,6 +20,7 @@ dependencies: - field.field.node.vba_facility.field_facility_locator_api_id - field.field.node.vba_facility.field_facility_vba_classificatio - field.field.node.vba_facility.field_geolocation + - field.field.node.vba_facility.field_intro_text - field.field.node.vba_facility.field_last_saved_by_an_editor - field.field.node.vba_facility.field_local_spotlight - field.field.node.vba_facility.field_media @@ -91,7 +92,6 @@ third_party_settings: group_editorial_workflow: children: - moderation_state - - revision_log - flag label: 'Editorial Workflow' region: content @@ -344,7 +344,7 @@ third_party_settings: show_empty_fields: '1' show_label: '1' tooltip_description: '' - description: 'Facility services are created on a different page.' + description: 'Adds a link to create a VBA Facility service. The actual content is overridden by changeLinkNewService() in va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php' required_fields: '1' id: facility-services classes: 'not-editable centralized' @@ -392,7 +392,8 @@ content: type: address_default weight: 11 region: content - settings: { } + settings: + wrapper_type: fieldset third_party_settings: { } field_administration: type: options_select diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index f561d142ee..97d826e279 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -156,7 +156,6 @@ protected function changeLinkNewService(FormIdAlterEvent $event): void { /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */ $form_object = $form_state->getFormObject(); $entity = $form_object->getEntity(); - $section_tid = $entity->field_administration->target_id; $facility_nid = $entity->nid->value; $link_url = '/node/add/vba_facility_service?field_administration=' . $section_tid . '&field_office=' . $facility_nid; From d9b0dd885096bcffeee506f303a12a9e00a9899a Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 2 Jul 2024 13:05:00 -0500 Subject: [PATCH 06/13] VACMS-17885: Adds second link --- .../src/EventSubscriber/VbaFacilitySubscriber.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index 97d826e279..ded9550eda 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -149,18 +149,25 @@ public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void { */ protected function changeLinkNewService(FormIdAlterEvent $event): void { $form = &$event->getForm(); + if (!isset($form["#fieldgroups"]["group_facility_services"])) { return; } + $form_state = $event->getFormState(); /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */ $form_object = $form_state->getFormObject(); $entity = $form_object->getEntity(); $section_tid = $entity->field_administration->target_id; $facility_nid = $entity->nid->value; - $link_url = '/node/add/vba_facility_service?field_administration=' . $section_tid . '&field_office=' . $facility_nid; + $add_new_service_url = "/node/add/vba_facility_service?field_administration=$section_tid&field_office=$facility_nid"; + $encoded_facility_name = urlencode($entity->title->value); + if (isset($form["#fieldgroups"]["group_facility_services"]->format_settings["description"])) { - $form["#fieldgroups"]["group_facility_services"]->format_settings["description"] = "To create a facility service Add another service"; + $form["#fieldgroups"]["group_facility_services"]->format_settings["description"] = " +

To create a facility service, visit the add VBA facility service form.

+

To see all services for this facility, visit the content search page (filtered for services of this facility).

+ "; } } From 509cf8f1a0fa4ad7fd29f6c26f7d7a1e6a95b6fe Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 2 Jul 2024 14:58:04 -0500 Subject: [PATCH 07/13] VACMS-17885: Updates link language per UX review --- .../src/EventSubscriber/VbaFacilitySubscriber.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index ded9550eda..244155e9ff 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -165,9 +165,9 @@ protected function changeLinkNewService(FormIdAlterEvent $event): void { if (isset($form["#fieldgroups"]["group_facility_services"]->format_settings["description"])) { $form["#fieldgroups"]["group_facility_services"]->format_settings["description"] = " -

To create a facility service, visit the add VBA facility service form.

-

To see all services for this facility, visit the content search page (filtered for services of this facility).

- "; +

Create a new service for this facility (opens in new window).

+

Manage existing services for this facility (opens in new window).

+ "; } } From d2a00d1c5344aa1499eda7d96cc7fc40265681b4 Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 2 Jul 2024 15:04:33 -0500 Subject: [PATCH 08/13] Updates config --- .../sync/core.entity_form_display.node.vba_facility.default.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/sync/core.entity_form_display.node.vba_facility.default.yml b/config/sync/core.entity_form_display.node.vba_facility.default.yml index d73514596f..ad7bd2ce7e 100644 --- a/config/sync/core.entity_form_display.node.vba_facility.default.yml +++ b/config/sync/core.entity_form_display.node.vba_facility.default.yml @@ -20,7 +20,6 @@ dependencies: - field.field.node.vba_facility.field_facility_locator_api_id - field.field.node.vba_facility.field_facility_vba_classificatio - field.field.node.vba_facility.field_geolocation - - field.field.node.vba_facility.field_intro_text - field.field.node.vba_facility.field_last_saved_by_an_editor - field.field.node.vba_facility.field_local_spotlight - field.field.node.vba_facility.field_media @@ -92,6 +91,7 @@ third_party_settings: group_editorial_workflow: children: - moderation_state + - revision_log - flag label: 'Editorial Workflow' region: content From 9e2a4f58833bc9803a3a0213de881550048a311e Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Tue, 2 Jul 2024 15:28:58 -0500 Subject: [PATCH 09/13] VACMS-17885: Removing unnecessary periods --- .../src/EventSubscriber/VbaFacilitySubscriber.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index 244155e9ff..1a65d0e402 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -165,8 +165,8 @@ protected function changeLinkNewService(FormIdAlterEvent $event): void { if (isset($form["#fieldgroups"]["group_facility_services"]->format_settings["description"])) { $form["#fieldgroups"]["group_facility_services"]->format_settings["description"] = " -

Create a new service for this facility (opens in new window).

-

Manage existing services for this facility (opens in new window).

+

Create a new service for this facility (opens in new window)

+

Manage existing services for this facility (opens in new window)

"; } } From fcd1fa1dfe92c4191245bb93fbccfa30278544ac Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Wed, 3 Jul 2024 09:01:30 -0500 Subject: [PATCH 10/13] VACMS-17885: Updates for readability after PR review --- .../EventSubscriber/VbaFacilitySubscriber.php | 62 ++++++++++++------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index 1a65d0e402..073c499b6b 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -20,7 +20,8 @@ /** * VA.gov VBA Facility Event Subscriber. */ -class VbaFacilitySubscriber implements EventSubscriberInterface { +class VbaFacilitySubscriber implements EventSubscriberInterface +{ use StringTranslationTrait; @@ -64,7 +65,7 @@ public function __construct( UserPermsService $user_perms_service, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer - ) { + ) { $this->stringTranslation = $string_translation; $this->userPermsService = $user_perms_service; $this->entityTypeManager = $entity_type_manager; @@ -74,7 +75,8 @@ public function __construct( /** * {@inheritdoc} */ - public static function getSubscribedEvents(): array { + public static function getSubscribedEvents(): array + { return [ EntityHookEvents::ENTITY_VIEW_ALTER => 'entityViewAlter', 'hook_event_dispatcher.form_node_vba_facility_edit_form.alter' => 'alterVbaFacilityNodeForm', @@ -90,7 +92,8 @@ public static function getSubscribedEvents(): array { * @param \Drupal\core_event_dispatcher\Event\Entity\EntityViewAlterEvent $event * The entity view alter service. */ - public function entityViewAlter(EntityViewAlterEvent $event):void { + public function entityViewAlter(EntityViewAlterEvent $event): void + { $this->appendServiceTermDescriptionToVbaFacilityService($event); } @@ -100,7 +103,8 @@ public function entityViewAlter(EntityViewAlterEvent $event):void { * @param \Drupal\core_event_dispatcher\Event\Entity\EntityViewAlterEvent $event * The entity view alter service. */ - public function appendServiceTermDescriptionToVbaFacilityService(EntityViewAlterEvent $event):void { + public function appendServiceTermDescriptionToVbaFacilityService(EntityViewAlterEvent $event): void + { $display = $event->getDisplay(); if (($display->getTargetBundle() === 'vba_facility_service') && ($display->getOriginalMode() === 'full')) { $build = &$event->getBuild(); @@ -115,11 +119,11 @@ public function appendServiceTermDescriptionToVbaFacilityService(EntityViewAlter $referenced_term_content = $view_builder->view($referenced_term, 'vba_facility_service'); $description = $this->renderer->renderRoot($referenced_term_content); } - } - else { + } else { $description = new FormattableMarkup( '
Notice: The national service description was not found.
', - []); + [] + ); } $formatted_markup = new FormattableMarkup($description, []); $build['field_service_name_and_descripti']['#suffix'] = $formatted_markup; @@ -132,7 +136,8 @@ public function appendServiceTermDescriptionToVbaFacilityService(EntityViewAlter * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void { + public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void + { $this->addStateManagementToBannerFields($event); $this->changeBannerType($event); $this->changeDismissibleOption($event); @@ -147,7 +152,8 @@ public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void { * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - protected function changeLinkNewService(FormIdAlterEvent $event): void { + protected function changeLinkNewService(FormIdAlterEvent $event): void + { $form = &$event->getForm(); if (!isset($form["#fieldgroups"]["group_facility_services"])) { @@ -160,14 +166,17 @@ protected function changeLinkNewService(FormIdAlterEvent $event): void { $entity = $form_object->getEntity(); $section_tid = $entity->field_administration->target_id; $facility_nid = $entity->nid->value; - $add_new_service_url = "/node/add/vba_facility_service?field_administration=$section_tid&field_office=$facility_nid"; + $create_service_url = "/node/add/vba_facility_service?field_administration=$section_tid&field_office=$facility_nid"; + $create_service_text = $this->t('Create a new service for this facility (opens in new window)'); $encoded_facility_name = urlencode($entity->title->value); + $manage_services_url = "/admin/content?title=$encoded_facility_name&type=vba_facility_service&moderation_state=All&owner=All"; + $manage_services_text = $this->t('Manage existing services for this facility (opens in new window)'); if (isset($form["#fieldgroups"]["group_facility_services"]->format_settings["description"])) { $form["#fieldgroups"]["group_facility_services"]->format_settings["description"] = " -

Create a new service for this facility (opens in new window)

-

Manage existing services for this facility (opens in new window)

- "; +

$create_service_text

+

$manage_services_text

+ "; } } @@ -177,7 +186,8 @@ protected function changeLinkNewService(FormIdAlterEvent $event): void { * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - public function addStateManagementToBannerFields(FormIdAlterEvent $event) { + public function addStateManagementToBannerFields(FormIdAlterEvent $event) + { $form = &$event->getForm(); $form['#attached']['library'][] = 'va_gov_vba_facility/set_banner_fields_to_required'; $selector = ':input[name="field_show_banner[value]"]'; @@ -229,7 +239,8 @@ public function addStateManagementToBannerFields(FormIdAlterEvent $event) { * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - protected function changeBannerType(FormIdAlterEvent $event) { + protected function changeBannerType(FormIdAlterEvent $event) + { // Add the '- Select a value -' option to replace '- None -'. $form = &$event->getForm(); if (isset($form['field_alert_type']['widget']['#options']) && array_key_exists('_none', $form['field_alert_type']['widget']['#options'])) { @@ -243,7 +254,8 @@ protected function changeBannerType(FormIdAlterEvent $event) { * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - protected function changeDismissibleOption(FormIdAlterEvent $event) { + protected function changeDismissibleOption(FormIdAlterEvent $event) + { // Remove N/A option, which is the result of not being a "required" field. $form = &$event->getForm(); if (isset($form['field_dismissible_option']['widget']['#options']) && array_key_exists('_none', $form['field_dismissible_option']['widget']['#options'])) { @@ -257,7 +269,8 @@ protected function changeDismissibleOption(FormIdAlterEvent $event) { * @param \Drupal\core_event_dispatcher\Event\Entity\EntityTypeAlterEvent $event * The event for entityTypeAlter. */ - public function entityTypeAlter(EntityTypeAlterEvent $event): void { + public function entityTypeAlter(EntityTypeAlterEvent $event): void + { $entity_types = $event->getEntityTypes(); if (!empty($entity_types['node'])) { $entity = $entity_types['node']; @@ -271,7 +284,8 @@ public function entityTypeAlter(EntityTypeAlterEvent $event): void { * @param \Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent $event * The event. */ - public function entityPresave(EntityPresaveEvent $event): void { + public function entityPresave(EntityPresaveEvent $event): void + { $entity = $event->getEntity(); if ($entity instanceof NodeInterface) { $this->clearBannerFields($entity); @@ -284,11 +298,14 @@ public function entityPresave(EntityPresaveEvent $event): void { * @param \Drupal\Core\Entity\EntityInterface $entity * Entity. */ - protected function clearBannerFields(EntityInterface $entity): void { + protected function clearBannerFields(EntityInterface $entity): void + { /** @var \Drupal\node\NodeInterface $entity */ if ($entity->bundle() === "vba_facility") { - if ($entity->hasField('field_show_banner') - && $entity->field_show_banner->value == FALSE) { + if ( + $entity->hasField('field_show_banner') + && $entity->field_show_banner->value == FALSE + ) { if ($entity->field_alert_type) { $entity->field_alert_type->value = NULL; } @@ -304,5 +321,4 @@ protected function clearBannerFields(EntityInterface $entity): void { } } } - } From eed79a75c46c887d67074c81ee7bb9f7cdec105b Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Wed, 3 Jul 2024 09:05:47 -0500 Subject: [PATCH 11/13] VACMS-17885: Reformatting --- .../EventSubscriber/VbaFacilitySubscriber.php | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index 073c499b6b..c85f863ef6 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -20,8 +20,7 @@ /** * VA.gov VBA Facility Event Subscriber. */ -class VbaFacilitySubscriber implements EventSubscriberInterface -{ +class VbaFacilitySubscriber implements EventSubscriberInterface { use StringTranslationTrait; @@ -75,8 +74,7 @@ public function __construct( /** * {@inheritdoc} */ - public static function getSubscribedEvents(): array - { + public static function getSubscribedEvents(): array { return [ EntityHookEvents::ENTITY_VIEW_ALTER => 'entityViewAlter', 'hook_event_dispatcher.form_node_vba_facility_edit_form.alter' => 'alterVbaFacilityNodeForm', @@ -92,8 +90,7 @@ public static function getSubscribedEvents(): array * @param \Drupal\core_event_dispatcher\Event\Entity\EntityViewAlterEvent $event * The entity view alter service. */ - public function entityViewAlter(EntityViewAlterEvent $event): void - { + public function entityViewAlter(EntityViewAlterEvent $event): void { $this->appendServiceTermDescriptionToVbaFacilityService($event); } @@ -103,8 +100,7 @@ public function entityViewAlter(EntityViewAlterEvent $event): void * @param \Drupal\core_event_dispatcher\Event\Entity\EntityViewAlterEvent $event * The entity view alter service. */ - public function appendServiceTermDescriptionToVbaFacilityService(EntityViewAlterEvent $event): void - { + public function appendServiceTermDescriptionToVbaFacilityService(EntityViewAlterEvent $event): void { $display = $event->getDisplay(); if (($display->getTargetBundle() === 'vba_facility_service') && ($display->getOriginalMode() === 'full')) { $build = &$event->getBuild(); @@ -119,11 +115,12 @@ public function appendServiceTermDescriptionToVbaFacilityService(EntityViewAlter $referenced_term_content = $view_builder->view($referenced_term, 'vba_facility_service'); $description = $this->renderer->renderRoot($referenced_term_content); } - } else { + } + else { $description = new FormattableMarkup( '
Notice: The national service description was not found.
', [] - ); + ); } $formatted_markup = new FormattableMarkup($description, []); $build['field_service_name_and_descripti']['#suffix'] = $formatted_markup; @@ -136,8 +133,7 @@ public function appendServiceTermDescriptionToVbaFacilityService(EntityViewAlter * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void - { + public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void { $this->addStateManagementToBannerFields($event); $this->changeBannerType($event); $this->changeDismissibleOption($event); @@ -152,8 +148,7 @@ public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - protected function changeLinkNewService(FormIdAlterEvent $event): void - { + protected function changeLinkNewService(FormIdAlterEvent $event): void { $form = &$event->getForm(); if (!isset($form["#fieldgroups"]["group_facility_services"])) { @@ -186,8 +181,7 @@ protected function changeLinkNewService(FormIdAlterEvent $event): void * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - public function addStateManagementToBannerFields(FormIdAlterEvent $event) - { + public function addStateManagementToBannerFields(FormIdAlterEvent $event) { $form = &$event->getForm(); $form['#attached']['library'][] = 'va_gov_vba_facility/set_banner_fields_to_required'; $selector = ':input[name="field_show_banner[value]"]'; @@ -239,8 +233,7 @@ public function addStateManagementToBannerFields(FormIdAlterEvent $event) * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - protected function changeBannerType(FormIdAlterEvent $event) - { + protected function changeBannerType(FormIdAlterEvent $event) { // Add the '- Select a value -' option to replace '- None -'. $form = &$event->getForm(); if (isset($form['field_alert_type']['widget']['#options']) && array_key_exists('_none', $form['field_alert_type']['widget']['#options'])) { @@ -254,8 +247,7 @@ protected function changeBannerType(FormIdAlterEvent $event) * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - protected function changeDismissibleOption(FormIdAlterEvent $event) - { + protected function changeDismissibleOption(FormIdAlterEvent $event) { // Remove N/A option, which is the result of not being a "required" field. $form = &$event->getForm(); if (isset($form['field_dismissible_option']['widget']['#options']) && array_key_exists('_none', $form['field_dismissible_option']['widget']['#options'])) { @@ -269,8 +261,7 @@ protected function changeDismissibleOption(FormIdAlterEvent $event) * @param \Drupal\core_event_dispatcher\Event\Entity\EntityTypeAlterEvent $event * The event for entityTypeAlter. */ - public function entityTypeAlter(EntityTypeAlterEvent $event): void - { + public function entityTypeAlter(EntityTypeAlterEvent $event): void { $entity_types = $event->getEntityTypes(); if (!empty($entity_types['node'])) { $entity = $entity_types['node']; @@ -284,8 +275,7 @@ public function entityTypeAlter(EntityTypeAlterEvent $event): void * @param \Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent $event * The event. */ - public function entityPresave(EntityPresaveEvent $event): void - { + public function entityPresave(EntityPresaveEvent $event): void { $entity = $event->getEntity(); if ($entity instanceof NodeInterface) { $this->clearBannerFields($entity); @@ -298,8 +288,7 @@ public function entityPresave(EntityPresaveEvent $event): void * @param \Drupal\Core\Entity\EntityInterface $entity * Entity. */ - protected function clearBannerFields(EntityInterface $entity): void - { + protected function clearBannerFields(EntityInterface $entity): void { /** @var \Drupal\node\NodeInterface $entity */ if ($entity->bundle() === "vba_facility") { if ( @@ -321,4 +310,5 @@ protected function clearBannerFields(EntityInterface $entity): void } } } + } From 6d906be842892576c8a54a18ad9cf99c01029802 Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Wed, 3 Jul 2024 09:16:35 -0500 Subject: [PATCH 12/13] VACMS-17885: Updates function name and comments. --- .../src/EventSubscriber/VbaFacilitySubscriber.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php index c85f863ef6..368cab86df 100644 --- a/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php +++ b/docroot/modules/custom/va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php @@ -137,18 +137,19 @@ public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void { $this->addStateManagementToBannerFields($event); $this->changeBannerType($event); $this->changeDismissibleOption($event); - $this->changeLinkNewService($event); + $this->createLinksFacilityServices($event); } /** - * Changes the link for adding a new VBA Facility service. + * Adds links for creating and managing facility services. * - * This prepopulates the section and facility for editorial convenience. + * One link prepopulates the section and facility for editorial convenience. + * One link goes to the content search page, passing in the facility name. * * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. */ - protected function changeLinkNewService(FormIdAlterEvent $event): void { + protected function createLinksFacilityServices(FormIdAlterEvent $event): void { $form = &$event->getForm(); if (!isset($form["#fieldgroups"]["group_facility_services"])) { From 0932b6ceabb225a3c6bf0b799c8513f539bc860f Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Wed, 3 Jul 2024 09:20:24 -0500 Subject: [PATCH 13/13] VACMS-17855: Updates config with new function name --- .../sync/core.entity_form_display.node.vba_facility.default.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/sync/core.entity_form_display.node.vba_facility.default.yml b/config/sync/core.entity_form_display.node.vba_facility.default.yml index ad7bd2ce7e..187982671e 100644 --- a/config/sync/core.entity_form_display.node.vba_facility.default.yml +++ b/config/sync/core.entity_form_display.node.vba_facility.default.yml @@ -344,7 +344,7 @@ third_party_settings: show_empty_fields: '1' show_label: '1' tooltip_description: '' - description: 'Adds a link to create a VBA Facility service. The actual content is overridden by changeLinkNewService() in va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php' + description: 'Adds a link to create a VBA Facility service. The actual content is overridden by createLinksFacilityServices() in va_gov_vba_facility/src/EventSubscriber/VbaFacilitySubscriber.php' required_fields: '1' id: facility-services classes: 'not-editable centralized'