Skip to content
Snippets Groups Projects

Add method to the base class for fetching the url

All threads resolved!
Files
4
@@ -12,6 +12,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Drupal\data_pipelines\Destination\DatasetDestinationPluginBase;
use Drupal\data_pipelines\Entity\DatasetInterface;
use Drupal\data_pipelines\Entity\DestinationInterface;
@@ -186,6 +187,27 @@ abstract class FileDestinationBase extends DatasetDestinationPluginBase implemen
return $this->getDirPath() . $this->getFilename($dataset);
}
/**
* Get the Url object for the file of the dataset.
*
* @param \Drupal\data_pipelines\Entity\DatasetInterface $dataset
* The dataset.
*
* @return \Drupal\Core\Url
* File Url.
*/
public function getFileUrl(DatasetInterface $dataset): Url {
$fileUri = $this->getFilePath($dataset);
$filePath = $this->fileSystem->realpath($fileUri);
// Add the timestamp as a cache-bursting parameter.
$timestamp = file_exists($filePath) ? filemtime($filePath) : time();
return Url::fromUri($fileUri, [
'query' => [
't' => $timestamp,
],
]);
}
/**
* Get the dataset filename.
*
Loading