Skip to main content
edited title
Link
Matt V.
  • 3k
  • 1
  • 22
  • 27

What is the syntax for using a contrib module's service from within a hook implementation?

Source Link
Matt V.
  • 3k
  • 1
  • 22
  • 27

What is the syntax for using a contrib module's service from within a hook?

I'm trying to get a list of objects from AWS using the S3fsService from the S3 File System module from within a hook_cron() implementation. The following code works:

// Fetch list of files in S3.
$config = \Drupal::config('s3fs.settings')->get();
$s3 = \Drupal\s3fs\S3fsService::getAmazonS3Client($config);
$iterator_args = ['Bucket' => $config['bucket']];
$iterator = $s3->getIterator('ListObjectVersions', $iterator_args);

…but I'm getting a message saying Deprecated function: Non-static method Drupal\s3fs\S3fsService::getAmazonS3Client() should not be called statically….

How should I be calling it differently?

Thanks!