diff --git a/packages/drupal/silverback_ai/modules/silverback_ai_import/silverback_ai_import.module b/packages/drupal/silverback_ai/modules/silverback_ai_import/silverback_ai_import.module index 1d9c8a265..1483185a9 100644 --- a/packages/drupal/silverback_ai/modules/silverback_ai_import/silverback_ai_import.module +++ b/packages/drupal/silverback_ai/modules/silverback_ai_import/silverback_ai_import.module @@ -167,11 +167,13 @@ function _silverback_ai_import_form_submit(array $form, FormStateInterface $form case ContentImportAiService::URL: $file = $url_value; break; + case ContentImportAiService::NONE: + break; default: $file = $form_state->getValue('file'); } - if ($type != ContentImportAiService::URL) { + if (in_array($type, [ContentImportAiService::DOCX, ContentImportAiService::PDF])) { $file = $service->createFileEntityFromDropzoneData($file); } diff --git a/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportAiService.php b/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportAiService.php index 2e20f41ed..e656409a9 100644 --- a/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportAiService.php +++ b/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportAiService.php @@ -29,6 +29,7 @@ final class ContentImportAiService { public const DOCX = 'docx'; public const URL = 'url'; public const PDF = 'pdf'; + public const NONE = 'none'; /** * Constructs a ContentImportAiService object. diff --git a/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportBatch.php b/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportBatch.php index 21b1a9202..28c62fed4 100644 --- a/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportBatch.php +++ b/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportBatch.php @@ -152,16 +152,28 @@ public static function finish(bool $success, array $results, array $operations) // @todo Improve that to respect also templates $implode = implode(PHP_EOL, $results['content']); $content = << + $implode - + EOD; // @todo Add post import process here try { - $node->body->value = $content; + + // @todo + $config = \Drupal::service('config.factory')->get('gutenberg.settings'); + $node_type = $node->type->getString(); + $gutenberg_template = $config->get($node_type . '_template') ? json_decode($config->get($node_type . '_template')) : NULL; + $init = ''; + // @todo We can do better than this + foreach ($gutenberg_template as $item) { + $init .= "\n"; + } + + $cleaned = str_replace('', $content, $init); + $node->body->value = $cleaned; $node->save(); } catch (\Exception $e) { // @todo diff --git a/packages/drupal/silverback_ai/modules/silverback_ai_import/src/Form/PageDropForm.php b/packages/drupal/silverback_ai/modules/silverback_ai_import/src/Form/PageDropForm.php index aaebdbab7..c55d1771f 100644 --- a/packages/drupal/silverback_ai/modules/silverback_ai_import/src/Form/PageDropForm.php +++ b/packages/drupal/silverback_ai/modules/silverback_ai_import/src/Form/PageDropForm.php @@ -214,11 +214,13 @@ public function submitForm(array &$form, FormStateInterface $form_state): void { case ContentImportAiService::URL: $file = $url_value; break; + case ContentImportAiService::NONE: + break; default: $file = $form_state->getValue('file'); } - if ($type != ContentImportAiService::URL) { + if (in_array($type, [ContentImportAiService::DOCX, ContentImportAiService::PDF])) { $file = $service->createFileEntityFromDropzoneData($file); } diff --git a/packages/drupal/silverback_ai/modules/silverback_ai_test/tests/src/Unit/ExampleTest.php b/packages/drupal/silverback_ai/modules/silverback_ai_test/tests/src/Unit/ExampleTest.php new file mode 100644 index 000000000..5a01a5081 --- /dev/null +++ b/packages/drupal/silverback_ai/modules/silverback_ai_test/tests/src/Unit/ExampleTest.php @@ -0,0 +1,31 @@ +