Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VACMS-17885: Create facility services links on VBA Facility page #18442

Merged
merged 13 commits into from
Jul 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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();
Expand All @@ -119,7 +119,8 @@ public function appendServiceTermDescriptionToVbaFacilityService(EntityViewAlter
else {
$description = new FormattableMarkup(
'<div><strong>Notice: The national service description was not found.</strong></div>',
[]);
[]
);
}
$formatted_markup = new FormattableMarkup($description, []);
$build['field_service_name_and_descripti']['#suffix'] = $formatted_markup;
Expand All @@ -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"] = "
<p><a href='$create_service_url' target='_blank'>$create_service_text</p>
<p><a href='$manage_services_url' target='_blank'>$manage_services_text</p>
";
}
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
Loading