public function PublicFileSchemeHandler::getFile in Acquia Content Hub 8.2
Same name in this branch
- 8.2 src/Plugin/FileSchemeHandler/PublicFileSchemeHandler.php \Drupal\acquia_contenthub\Plugin\FileSchemeHandler\PublicFileSchemeHandler::getFile()
- 8.2 tests/src/Kernel/Stubs/PublicFileSchemeHandler.php \Drupal\Tests\acquia_contenthub\Kernel\Stubs\PublicFileSchemeHandler::getFile()
Makes file available to Drupal through the correct stream wrapper.
This does not return the file, but will save it with the appropriate stream wrapper for Drupal to utilize.
Parameters
\Acquia\ContentHubClient\CDF\CDFObject $object: The CDFObject from which to extract details about getting the file.
Return value
bool Whether the file successfully saved or not.
Overrides PublicFileSchemeHandler::getFile
File
- tests/
src/ Kernel/ Stubs/ PublicFileSchemeHandler.php, line 21
Class
- PublicFileSchemeHandler
- Handler for public files.
Namespace
Drupal\Tests\acquia_contenthub\Kernel\StubsCode
public function getFile(CDFObject $object) {
if ($object
->getAttribute('file_location') && $object
->getAttribute('file_uri')) {
$url = $object
->getAttribute('file_location')
->getValue()['und'];
$url = str_replace('module::', drupal_get_path('module', 'acquia_contenthub'), $url);
$contents = file_get_contents($url);
$uri = $object
->getAttribute('file_uri')
->getValue()['und'];
try {
return \Drupal::service('file_system')
->saveData($contents, $uri, FileSystemInterface::EXISTS_REPLACE);
} catch (FileWriteException $e) {
\Drupal::messenger()
->addError(t('The file could not be created.'));
return FALSE;
} catch (FileException $e) {
return FALSE;
}
}
return FALSE;
}