Skip to content

Commit 9ee0917

Browse files
committed
fix(drupal): Use localgov_services_page for PDF conversion
LocalGov Drupal doesn't have a 'page' content type. Changed the PDF-to-Web conversion createNode endpoint to use 'localgov_services_page' instead, which does exist and has the required body field. Fixes 500 error when creating draft pages from converted PDFs.
1 parent 6182e42 commit 9ee0917

1 file changed

Lines changed: 2 additions & 17 deletions

File tree

cloudformation/scenarios/localgov-drupal/drupal/web/modules/custom/ndx_aws_ai/src/Controller/PdfConversionController.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -241,32 +241,17 @@ public function createNode(Request $request): JsonResponse {
241241
// Create the page node.
242242
$nodeStorage = $this->entityTypeManager()->getStorage('node');
243243

244+
// Use localgov_services_page content type (LocalGov Drupal doesn't have 'page').
244245
$node = $nodeStorage->create([
245-
'type' => 'page',
246+
'type' => 'localgov_services_page',
246247
'title' => $title,
247248
'body' => [
248249
'value' => $result['html'],
249250
'format' => 'full_html',
250251
],
251252
'status' => 0, // Unpublished (draft).
252-
'field_pdf_converted' => TRUE,
253253
]);
254254

255-
// Attach original PDF if we have the file ID.
256-
if (preg_match('/^pdf_(\d+)_/', $jobId, $matches)) {
257-
$fileId = (int) $matches[1];
258-
$file = $this->entityTypeManager()->getStorage('file')->load($fileId);
259-
if ($file) {
260-
// If the node type has a file field, attach it.
261-
if ($node->hasField('field_attachments')) {
262-
$node->set('field_attachments', [
263-
'target_id' => $fileId,
264-
'description' => 'Original PDF document',
265-
]);
266-
}
267-
}
268-
}
269-
270255
$node->save();
271256

272257
$this->logger->info('Created draft node @nid from PDF conversion @job', [

0 commit comments

Comments
 (0)