Commit 182d8632 authored by Coby Sher's avatar Coby Sher Committed by Brian Perry
Browse files

Issue #3243572 by coby.sher, brianperry: Document how to use getObject to get...

Issue #3243572 by coby.sher, brianperry: Document how to use getObject to get menu items from Drupal
parent a3270a74
Loading
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ async function main(): Promise<void> {
      objectName: 'node--recipe',
    })
  );

  console.log('--- Get collection from state if it already exists ---');
  console.log(
    await store.getObject({
@@ -162,6 +163,12 @@ async function main(): Promise<void> {
    })
  );

  // It is possible to fetch menu data using the jsonapi_menu_items module along with jsonapi_hypermedia
  // jsonapi_hypermedia module: https://www.drupal.org/project/jsonapi_hypermedia
  // jsonapi_menu_items module: https://www.drupal.org/project/jsonapi_menu_items
  console.log('--- Fetch Menu items---');
  console.log(await store.getObject({ objectName: 'menu_items--main' }));

  console.log(store.getState());
  // Uncomment to use authenticated store - currently depends on local environment

+2 −1
Original line number Diff line number Diff line
@@ -44,8 +44,9 @@ export const SIDEBAR = {
    { text: 'GraphQL Queries (Experimental)', link: 'en/graphql-queries' },
    { text: 'Authorization', link: 'en/authorization' },

    { text: 'Additional Features', header: true },
    { text: 'Common Use Cases', header: true },
    { text: 'Getting Objects by Path', link: 'en/get-object-by-path' },
    { text: 'Getting Menu Items', link: 'en/getting-menu-items' },
    { text: 'Utilities', link: 'en/utilities' },

    { text: 'Project Direction', header: true },
+17 −0
Original line number Diff line number Diff line
---
title: Getting Menu Items
layout: ../../layouts/MainLayout.astro
---

The `getObject` method can also be used to source menu data from Drupal if the
`jsonapi_hypermedia` and `jsonapi_menu_items` modules are enabled.

See https://www.drupal.org/project/jsonapi_hypermedia and
https://www.drupal.org/project/jsonapi_menu_items for more details on enabling
those modules in your Drupal instance.

```js
const menuItems = await store.getObject({
  objectName: 'menu_items--main', // Fetches the menu named `main`
});
```