From f3c3bb551bd1ed025f2ca45223570a724a81c827 Mon Sep 17 00:00:00 2001 From: sharmasahil Date: Wed, 29 Jan 2025 13:27:05 +1100 Subject: [PATCH] Privatfile source for dataset --- .../src/Source/Resource/PrivateFile.php | 57 +++++++++++++++++++ .../tide_data_pipeline.services.yml | 5 ++ 2 files changed, 62 insertions(+) create mode 100644 modules/tide_search/modules/tide_data_pipeline/src/Source/Resource/PrivateFile.php create mode 100644 modules/tide_search/modules/tide_data_pipeline/tide_data_pipeline.services.yml diff --git a/modules/tide_search/modules/tide_data_pipeline/src/Source/Resource/PrivateFile.php b/modules/tide_search/modules/tide_data_pipeline/src/Source/Resource/PrivateFile.php new file mode 100644 index 000000000..51f78289e --- /dev/null +++ b/modules/tide_search/modules/tide_data_pipeline/src/Source/Resource/PrivateFile.php @@ -0,0 +1,57 @@ +getFileUri()) { + // Ensure the file is part of the private files folder. + $file_uri = $file->getFileUri(); + if (strpos($file_uri, 'private://') === 0) { + return fopen($file_uri, 'r'); + } + } + } + return NULL; + } + + /** + * {@inheritDoc} + */ + public function getResourceBaseFieldDefinition(array $source_plugin_definition): BaseFieldDefinition { + // Create the field definition for the file. + $field_definition = BaseFieldDefinition::create('file') + ->setLabel(new TranslatableMarkup('Private File')) + ->setDescription(new TranslatableMarkup('The file for the dataset.')) + ->setSetting('file_extensions', $source_plugin_definition['id']) + ->setRequired(TRUE) + ->setDisplayOptions('form', [ + 'type' => 'file_generic', + ]); + + // Set the upload location to the private directory. + $field_definition->setSetting('file_directory', 'private://'); + + return $field_definition; + } + +} diff --git a/modules/tide_search/modules/tide_data_pipeline/tide_data_pipeline.services.yml b/modules/tide_search/modules/tide_data_pipeline/tide_data_pipeline.services.yml new file mode 100644 index 000000000..ad942cd3e --- /dev/null +++ b/modules/tide_search/modules/tide_data_pipeline/tide_data_pipeline.services.yml @@ -0,0 +1,5 @@ +services: + tide_data_pipeline.source_resource.privatefile: + class: Drupal\tide_data_pipeline\Source\Resource\PrivateFile + tags: + - { name: data_pipelines_source_resource }