-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Issue #3336148: Add support for drupal-forms (#247)
* feat: Issue #3336148: Add support for forms * LDP-2492: Remove unnecessary if * LDP-2492: Improve redirect code * LDP-2492: Improve internal redirect code * LDP-2492: Revert redirect code * LDP-2492: Improve code and use page middleware * LDP-2492: Add server middleware and error handling * LDP-2492: Move middleware to module * LDP-2492: Include error message commit * LDP-2492: Add imports
- Loading branch information
1 parent
a45ce16
commit 22213f3
Showing
6 changed files
with
89 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<template> | ||
<form :formId="formId" :method="method" v-bind="attributes" :action="useRoute().fullPath" class="drupal-form"> | ||
<slot><div v-html="content" /></slot> | ||
</form> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const props = defineProps<{ | ||
formId: String, | ||
attributes: Object, | ||
method: String, | ||
content?: String, | ||
}>() | ||
</script> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { defineEventHandler, readFormData } from 'h3' | ||
import { getDrupalBaseUrl } from '../../composables/useDrupalCe/server' | ||
import { useRuntimeConfig } from '#imports' | ||
|
||
export default defineEventHandler(async (event) => { | ||
const { ceApiEndpoint } = useRuntimeConfig().public.drupalCe | ||
|
||
if (event.node.req.method === 'POST') { | ||
const formData = await readFormData(event) | ||
|
||
if (formData) { | ||
const targetUrl = event.node.req.url | ||
const response = await $fetch.raw(getDrupalBaseUrl() + ceApiEndpoint + targetUrl, { | ||
method: 'POST', | ||
body: formData, | ||
}).catch((error) => { | ||
event.context.drupalCeCustomPageResponse = { | ||
error: { | ||
data: error, | ||
statusCode: error.statusCode || 400, | ||
message: error.message || 'Error when POSTing form data (drupalFormHandler).', | ||
}, | ||
} | ||
}) | ||
|
||
if (response) { | ||
event.context.drupalCeCustomPageResponse = { | ||
_data: response._data, | ||
headers: Object.fromEntries(response.headers.entries()), | ||
} | ||
} | ||
} else { | ||
throw createError({ | ||
statusCode: 400, | ||
statusMessage: 'Bad Request', | ||
message: 'POST requests without form data are not supported (drupalFormHandler).', | ||
}) | ||
} | ||
} | ||
}) |