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 FileSchemeHandlerInterface::getFile
1 method overrides PublicFileSchemeHandler::getFile()
- PublicFileSchemeHandler::getFile in tests/
src/ Kernel/ Stubs/ PublicFileSchemeHandler.php - Makes file available to Drupal through the correct stream wrapper.
File
- src/
Plugin/ FileSchemeHandler/ PublicFileSchemeHandler.php, line 99
Class
- PublicFileSchemeHandler
- The handler for files with a public file scheme.
Namespace
Drupal\acquia_contenthub\Plugin\FileSchemeHandlerCode
public function getFile(CDFObject $object) {
if ($object
->getAttribute('file_location') && $object
->getAttribute('file_uri')) {
$url = $object
->getAttribute('file_location')
->getValue()[LanguageInterface::LANGCODE_NOT_SPECIFIED];
$uri = $object
->getAttribute('file_uri')
->getValue()[LanguageInterface::LANGCODE_NOT_SPECIFIED];
$dirname = $this->fileSystem
->dirname($uri);
if ($this->fileSystem
->prepareDirectory($dirname, FileSystemInterface::CREATE_DIRECTORY)) {
$contents = file_get_contents($url);
return $this
->saveData($contents, $uri, FileSystemInterface::EXISTS_REPLACE);
}
}
return FALSE;
}