Problem/Motivation
When I try to create a Text (formatted, long) field in Media Type: Document, I get an error.
Steps to reproduce
I am using the tutorial in this link: Link Here: to read PDF's using this module. I have followed succesfully the tutorial up to the stage where he is trying to create field in the Media Type Document. When I try to create a Formatted Text Long field I get the following error:
Fatal error: Declaration of Drupal\ai_interpolator_convertapi\TextDocument::generate(string $prompt, Drupal\Core\Entity\ContentEntityInterface $entity, Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition, array $interpolatorConfig) must be compatible with Drupal\ai_interpolator\Annotation\AiInterpolatorFieldRule::generate(Drupal\Core\Entity\ContentEntityInterface $entity, Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition, array $interpolatorConfig) in /var/www/html/web/modules/contrib/ai_interpolator_convertapi/src/TextDocument.php on line 135
I have tried make a Unformatted Text Long field and I have the same issue, however, when I try to create an Unformatted Text Short field is looks like it's working just fine. I don't know what is the issue.
Looking into the code, I see that the line 135 from that file is this function:
<?php
public function generate(string $prompt, ContentEntityInterface $entity, FieldDefinitionInterface $fieldDefinition, array $interpolatorConfig) {
// Field and api key has to be set.
if (empty($entity->{$interpolatorConfig['base_field']}) || !$this->apiKey) {
return [];
}
$values = [];
ConvertApi::setApiSecret($this->apiKey);
foreach ($entity->{$interpolatorConfig['base_field']} as $wrapperEntity) {
$fileEntity = $wrapperEntity->entity;
// Just allow PDF, Excel and Word files.
if (in_array($fileEntity->getMimeType(), [
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/pdf',
])) {
$result = ConvertApi::convert('txt', ['File' => $fileEntity->getFileUri()]);
$values[] = $result->getFile()->getContents();
}
}
return $values;
}
?>
I don't really know what is happening in this function to be honest, I hope someone can help.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes