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 changeLinkNewService() 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 @@ -136,6 +136,39 @@ public function alterVbaFacilityNodeForm(FormIdAlterEvent $event): void {
$this->addStateManagementToBannerFields($event);
$this->changeBannerType($event);
$this->changeDismissibleOption($event);
$this->changeLinkNewService($event);
}

/**
* 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.
*/
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;
$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"] = "
<p><a href='$add_new_service_url' target='_blank'>Create a new service for this facility (opens in new window)</a></p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHOULD...
...use a more structured approach to the markup here to support readability and ultimately translations. eg:

  $form["#fieldgroups"]["group_facility_services"]->format_settings["description"]['create'] = [
    '#title' => $this->t('Create a new service for this facility (opens in new window)'),
    '#type' => 'link',
    '#url' => // the url,
    '#prefix' => '<p>',
    '#suffix' => '</p>',
  ];
  $form["#fieldgroups"]["group_facility_services"]->format_settings["description"]['manage'] = [
    '#title' => $this->t('Manage existing services for this facility (opens in new window)'),
    '#type' => 'link',
    '#url' => // the url,
    '#prefix' => '<p>',
    '#suffix' => '</p>',
  ];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to implement this, but kept getting errors that appear to be related to how ['description'] is expecting a string, not an array.
Screenshot 2024-07-03 at 8 46 11 AM

I wrapped the link text in a t() and made it all a little more readable.

$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>
        ";
    }

<p><a href='/admin/content?title=$encoded_facility_name&type=vba_facility_service&moderation_state=All&owner=All' target='_blank'>Manage existing services for this facility (opens in new window)</a></p>
";
}
}

/**
Expand Down
Loading