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..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: 'Facility services are created on a different page.' + 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' @@ -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/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..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 @@ -64,7 +64,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; @@ -90,7 +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); } @@ -100,7 +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,7 +119,8 @@ public function appendServiceTermDescriptionToVbaFacilityService(EntityViewAlter 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,6 +137,43 @@ public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void { $this->addStateManagementToBannerFields($event); $this->changeBannerType($event); $this->changeDismissibleOption($event); + $this->createLinksFacilityServices($event); + } + + /** + * Adds links for creating and managing facility services. + * + * 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 createLinksFacilityServices(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; + $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_service_text

+

$manage_services_text

+ "; + } } /** @@ -254,8 +292,10 @@ public function entityPresave(EntityPresaveEvent $event): 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; }