function acquia_contenthub_s3_file_insert in Acquia Content Hub 8.2
Implements hook_ENTITY_TYPE_insert().
File
- modules/
acquia_contenthub_s3/ acquia_contenthub_s3.module, line 29 - Drupal Module: Acquia Content Hub S3.
Code
function acquia_contenthub_s3_file_insert(FileInterface $entity) {
$scheme = StreamWrapperManager::getScheme($entity
->getFileUri());
if ($scheme !== 's3') {
return;
}
// Map the s3 file to avoid unnecessary requests in the future due to file
// location discovery.
/** @var \Drupal\acquia_contenthub_s3\S3FileMap $file_map */
$file_map = \Drupal::getContainer()
->get('acquia_contenthub_s3.file_map');
$config_factory = \Drupal::configFactory();
$s3fs_config = $config_factory
->get('s3fs.settings');
/** @var \Acquia\ContentHubClient\ContentHubClient $ch_client */
$ch_client = \Drupal::getContainer()
->get('acquia_contenthub.client.factory')
->getClient();
if (!$ch_client) {
return;
}
if (!$file_map
->isNew($entity
->uuid())) {
return;
}
$file_map
->record($entity
->uuid(), $s3fs_config
->get('bucket'), $s3fs_config
->get('root_folder'), $ch_client
->getSettings()
->getUuid());
}