Closed timcosgrove closed 2 years ago
How this currently works:
(added links to where in content-build this menu selection happens. In this function page is the json structure of the current page being rendered; contentData is the entire GraphQL response.
So in a sense, the facility sidebar menus are already tied to a given VAMC/system's pages through field_office. It's just, it is dependent on there being a menu object that happens to have that same name. As an example,
One hiccup is that, Drupal itself does not tie a menu entity and its associated menu link content entities in a properly referenced way. For example, if we add a reference to a menu as a field on a content type, JSON:API returns this type of structure:
"field_system_menu": {
"data": {
"type": "menu--menu",
"id": "518f7bfb-cdaa-4da3-be5c-a408accd2213",
"meta": {
"drupal_internal__target_id": "va-alexandria-health-care"
}
},
"links": {
"related": {
"href": "https://va-gov-cms.ddev.site/jsonapi/node/health_care_region_page/178b8006-d7f0-4afc-a15f-1d4b021cbb2f/field_system_menu?resourceVersion=id%3A657872"
},
"self": {
"href": "https://va-gov-cms.ddev.site/jsonapi/node/health_care_region_page/178b8006-d7f0-4afc-a15f-1d4b021cbb2f/relationships/field_system_menu?resourceVersion=id%3A657872"
}
}
},
There is not a way for Drupal to make the jump to retrieve the actual menu links. We can take the machine name of the menu from the above response, and use that to find the menu links and retrieve them via a second API call.
One way around this is to use JSON:API Extras' concept of an Enhancer to augment the JSON:API response with the data we need. Enhancers are plugins which take Drupal data and modify it prior to being output in the JSON:API response. Here are examples included with the module: https://git.drupalcode.org/project/jsonapi_extras/-/tree/8.x-3.x/src/Plugin/jsonapi/FieldEnhancer
Given JSON:API output which includes a reference to a specific menu, we can use an Enhancer plugin to retrieve the menu links for that menu and then provide them as part of the JSON:API response.
Some of the code in this block plugin could most likely be refactored to provide the menu link tree to the enhancer: https://github.com/department-of-veterans-affairs/va.gov-cms/blob/main/docroot/modules/custom/va_gov_backend/src/Plugin/Block/SidebarMenusBlock.php
Meaning, refactor the code that retrieves and processes the menu tree into its own files, and make use of it both in this block and in a JSON:API enhancer.
menu
entities on the VAMC System type (health_care_region_page
). Once this is in prod, it should be a mob session task to assign the appropriate menu to each system. If 2 is a non starter, there is an alternate route:
https://github.com/department-of-veterans-affairs/va.gov-cms/issues/9520 for the first part of this.
Description
Spike to dive a little deeper into how facility menus are referenced and output into Metalsmith/content-build pages, so we know better how to proceed for next-build.
Acceptance Criteria
[x] Determine how menus will be associated with their corresponding next-build pages (https://github.com/department-of-veterans-affairs/va.gov-cms/issues/8693#issuecomment-1158862495)
[x] Create followup tickets for implementation
NOTE: discuss with Sitewide CMS how menus can be explicitly linked to facility pages
CMS Team
Please check the team(s) that will do this work.
Sitewide program
Platform CMS Team
Sitewide crew
(leave Sitewide unchecked and check the specific team instead)⭐️ Content ops
⭐️ CMS experience
⭐️ Public websites
⭐️ Facilities
⭐️ User support