Skip to content

Commit d057633

Browse files
authored
feat: LDP-1749: Add support for language prefix for menu API calls (#87)
* feat: LDP-1749: Add support for language prefix for menu API calls. * feat: LDP-1749: Use localized menu endpoints only if enabled in module options.
1 parent 98f25f1 commit d057633

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ You may also take a look at the [example project](https://github.com/drunomics/l
6565
`$$$NAME$$$` is replaced by the menu name being fetched. To enable menu fetching, un-comment the nuxtServerInit action
6666
in `store/init.js`.
6767

68+
- `useLocalizedMenuEndpoint`: If enabled, the menu endpoint will use a language prefix as configured by [nuxtjs/i18n](https://i18n.nuxtjs.org) module. Defaults to `true`.
69+
6870
- `useProxy`: If set to `dev-only` and nuxt is in dev-mode, the module automatically
6971
configures `/api` to the Drupal backend via
7072
[@nuxtjs/proxy](https://github.com/nuxt-community/proxy-module) and uses it instead of

lib/module.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ async function drupalCe (moduleOptions) {
77
const defaultOptions = {
88
baseURL: process.env.DRUPAL_BASE_URL || 'http://localhost:8888',
99
menuEndpoint: 'api/menu_items/$$$NAME$$$',
10+
useLocalizedMenuEndpoint: true,
1011
addRequestFormat: 'custom_elements',
1112
addRequestContentFormat: false,
1213
addVueCompiler: true,

lib/plugin.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ const storeModule = {
199199
},
200200
async getMenu ({ commit }, { name, config, context, options, axios }) {
201201
config.params = config.params ?? {}
202-
const path = options.menuEndpoint.replace('$$$NAME$$$', name)
202+
let path = options.menuEndpoint.replace('$$$NAME$$$', name)
203+
if (options.useLocalizedMenuEndpoint && this.$i18n) {
204+
// API path with localization
205+
path = this.localePath('/' + path)
206+
}
203207
try {
204208
const { data } = await axios.get(path, config)
205209
commit('setMenu', { name, data })

0 commit comments

Comments
 (0)