Composables
The composable provided by the module provides helpers to fetch page and menu data, handle errors, and render custom components.
useDrupalCe
This composable exports a collection of utilities to handle Drupal content and functionality.
Page Handling
fetchPage(path: string, query?: Object, errorHandler?: Function, skipProxy?: boolean)
- Fetches a page by pathgetPage()
- Returns the current page stateusePageHead(page: Ref<any>, include?: Array<'title' | 'meta' | 'link' | 'jsonld'>)
- Sets page head metadata from Drupal datagetPageLayout(page?: Ref<any>)
- Gets current page layout name (defaults to 'default')
Menu Handling
fetchMenu(name: string, options?: Object, errorHandler?: Function, skipProxy?: boolean)
- Fetches a menu by name
Component Rendering
renderCustomElements(elements: string | object | Array)
- Renders one or multiple custom elements from JSON dataresolveCustomElement(element: string)
- Resolves a custom element name to a Vue component
Messages
getMessages()
- Returns Drupal messages of the current page
API Utilities
$ceApi(options?: Object, skipProxy?: boolean)
- Creates a configured fetch instanceuseCeApi(path: string, options?: Object, passThroughHeaders?: boolean, skipProxy?: boolean)
- Fetches data from Drupal CE API endpointgetCeApiEndpoint(localize?: boolean)
- Gets API endpoint with optional localizationgetDrupalBaseUrl()
- Gets configured Drupal base URLgetMenuBaseUrl()
- Gets configured menu base URL
Example usage
The following example makes use of the fetchPage
method to get the current page:
<script setup>
const { fetchPage } = useDrupalCe()
const page = await fetchPage(useRoute().path)
</script>
Table of Contents