From c4c93935df7ec3da90a9dff9a49bc964e28025fa Mon Sep 17 00:00:00 2001
From: Marcus Johansson <me@marcusmailbox.com>
Date: Fri, 17 May 2024 10:34:33 +0200
Subject: [PATCH] Issue #3447795 by Marcus_Johansson: The directory needs to be
 prepared in the filehlper

---
 .../AiEvaluationTool/AiInterpolatorTool.php     | 17 +++++++++++++++++
 src/Rulehelpers/FileHelper.php                  |  4 +++-
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 src/Plugin/AiEvaluationTool/AiInterpolatorTool.php

diff --git a/src/Plugin/AiEvaluationTool/AiInterpolatorTool.php b/src/Plugin/AiEvaluationTool/AiInterpolatorTool.php
new file mode 100644
index 0000000..3559ccb
--- /dev/null
+++ b/src/Plugin/AiEvaluationTool/AiInterpolatorTool.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace Drupal\ai_interpolator\Plugin\AiEvaluationTool;
+
+use Drupal\ai_evaluation\PluginInterface\AiToolPluginInterface;
+use Drupal\ai_evaluation\Attribute\AiTool;
+use Drupal\Core\StringTranslation\TranslatableMarkup;
+
+
+#[AiTool(
+  id: 'ai_interpolator_tool',
+  label: new TranslatableMarkup('AI Interpolator'),
+  description: new TranslatableMarkup('Use the AI Interpolator to compare workflows.'),
+)]
+class AiInterpolatorTool implements AiToolPluginInterface {
+
+}
diff --git a/src/Rulehelpers/FileHelper.php b/src/Rulehelpers/FileHelper.php
index a0775c3..346a922 100644
--- a/src/Rulehelpers/FileHelper.php
+++ b/src/Rulehelpers/FileHelper.php
@@ -86,7 +86,9 @@ class FileHelper {
    */
   public function createFilePathFromFieldConfig($fileName, FieldDefinitionInterface $fieldDefinition, ContentEntityInterface $entity) {
     $config = $fieldDefinition->getConfig($entity->bundle())->getSettings();
-    return $this->token->replace($config['uri_scheme'] . '://' . rtrim($config['file_directory'], '/')) . '/' . $fileName;
+    $path = $this->token->replace($config['uri_scheme'] . '://' . rtrim($config['file_directory'], '/'));
+    $this->fileSystem->prepareDirectory($path);
+    return $path . '/' . $fileName;
   }
 
   /**
-- 
GitLab