public function TextExtractorFormSettings::getTestFile in Search API attachments 8
Same name and namespace in other branches
- 9.0.x src/Form/TextExtractorFormSettings.php \Drupal\search_api_attachments\Form\TextExtractorFormSettings::getTestFile()
Helper method to get/create a pdf test file and extract its data.
The file created is then deleted after successful extraction.
Return value
object $file
1 call to TextExtractorFormSettings::getTestFile()
- TextExtractorFormSettings::submitForm in src/
Form/ TextExtractorFormSettings.php - Form submission handler.
File
- src/
Form/ TextExtractorFormSettings.php, line 325
Class
- TextExtractorFormSettings
- Configuration form.
Namespace
Drupal\search_api_attachments\FormCode
public function getTestFile() {
$filepath = 'public://search_api_attachments_test_extraction.pdf';
$values = [
'uri' => $filepath,
];
$file = $this->entityTypeManager
->getStorage('file')
->loadByProperties($values);
if (empty($file)) {
// Copy the source file to public directory.
$source = drupal_get_path('module', 'search_api_attachments');
$source .= '/data/search_api_attachments_test_extraction.pdf';
copy($source, $filepath);
// Create the file object.
$file = File::create([
'uri' => $filepath,
'uid' => $this
->currentUser()
->id(),
]);
$file
->save();
}
else {
$file = reset($file);
}
return $file;
}