Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions playground/server/routes/ce-api/node/unified.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export default defineEventHandler(() => ({
title: 'Another page',
messages: [],
breadcrumbs: [],
metatags: {},
content_format: 'json',
content: {
element: 'node',
slots: {
image: '<img loading="lazy" src="https://placehold.co/600x400" width="600" height="400" alt="test" />',
body: {
element: 'node',
Copy link
Contributor

Choose a reason for hiding this comment

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

this is bad example. a node-element is usually not wrapped in a node element. rather us a drupal-markup here.
also "unified" is a bad name, call it explicit.

slots: {
body: '<p>2nd <b>example</b> body.</p>',
},
props: {
title: 'Title2',
},
},
},
props: {
title: 'Title',
},
},
page_layout: 'clear',
local_tasks: [],
}))
12 changes: 11 additions & 1 deletion src/runtime/composables/useDrupalCe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,17 @@ export const useDrupalCe = () => {
// Handle single custom element object
const { element, ...props } = customElements
const resolvedElement = resolveCustomElement(element)
return resolvedElement ? h(resolvedElement, props) : null

// Handle slots
const slots = {}
if (customElements?.slots && Object.keys(customElements?.slots)?.length) {
Object.entries(customElements?.slots).forEach(([key, element]) => {
const rendered = renderCustomElements(element)
slots[key] = rendered ? () => h(rendered) : null
Copy link
Contributor

Choose a reason for hiding this comment

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

renderCustomElements already returns the return value of h() - so why are we wrapping it in another h() ?

})
}

return resolvedElement ? h(resolvedElement, { ...props, ...props.props }, slots) : null
}

/**
Expand Down