class S3FileSchemeHandler in Acquia Content Hub 8.2
S3 file scheme handler.
Plugin annotation
@FileSchemeHandler(
id = "s3",
label = @Translation("Amazon S3 file handler")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\acquia_contenthub_s3\Plugin\FileSchemeHandler\S3FileSchemeHandler implements FileSchemeHandlerInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of S3FileSchemeHandler
File
- modules/
acquia_contenthub_s3/ src/ Plugin/ FileSchemeHandler/ S3FileSchemeHandler.php, line 24
Namespace
Drupal\acquia_contenthub_s3\Plugin\FileSchemeHandlerView source
class S3FileSchemeHandler extends PluginBase implements FileSchemeHandlerInterface, ContainerFactoryPluginInterface {
/**
* The stream wrapper manager.
*
* @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
*/
protected $streamWrapperManager;
/**
* The s3fs.settings configuration.
*
* @var \Drupal\Core\Config\Config
*/
protected $s3fsConfig;
/**
* The s3 file mapper service.
*
* @var \Drupal\acquia_contenthub_s3\S3FileMapper
*/
protected $s3FileMapper;
/**
* S3FileSchemeHandler constructor.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin id.
* @param mixed $plugin_definition
* The definition.
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
* The stream wrapper manager service.
* @param \Drupal\Core\Config\Config $config
* The s3fs.settings configuration object.
* @param \Drupal\acquia_contenthub_s3\S3FileMapper $s3_file_mapper
* The s3 file mapper service.
*/
public function __construct(array $configuration, string $plugin_id, $plugin_definition, StreamWrapperManagerInterface $stream_wrapper_manager, Config $config, S3FileMapper $s3_file_mapper) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->streamWrapperManager = $stream_wrapper_manager;
$this->s3fsConfig = $config;
$this->s3FileMapper = $s3_file_mapper;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('stream_wrapper_manager'), $container
->get('config.factory')
->get('s3fs.settings'), $container
->get('acquia_contenthub_s3.file_mapper'));
}
/**
* {@inheritdoc}
*
* @throws \Exception
*/
public function addAttributes(CDFObject $object, FileInterface $file) {
$uri = $file
->getFileUri();
$streamWrapper = $this->streamWrapperManager
->getViaUri($uri);
$url = $streamWrapper
->getExternalUrl();
$object
->addAttribute('file_scheme', CDFAttribute::TYPE_STRING, 's3');
$object
->addAttribute('file_location', CDFAttribute::TYPE_STRING, $url);
$object
->addAttribute('file_uri', CDFAttribute::TYPE_STRING, $uri);
$object
->addAttribute('ach_s3_bucket', CDFAttribute::TYPE_STRING, $this->s3fsConfig
->get('bucket'));
$object
->addAttribute('ach_s3_source', CDFAttribute::TYPE_STRING, $this->s3fsConfig
->get('root_folder'));
}
/**
* {@inheritdoc}
*/
public function getFile(CDFObject $object) {
// No import needed, file is served from s3 bucket.
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
S3FileSchemeHandler:: |
protected | property | The s3 file mapper service. | |
S3FileSchemeHandler:: |
protected | property | The s3fs.settings configuration. | |
S3FileSchemeHandler:: |
protected | property | The stream wrapper manager. | |
S3FileSchemeHandler:: |
public | function |
Overrides FileSchemeHandlerInterface:: |
|
S3FileSchemeHandler:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
S3FileSchemeHandler:: |
public | function |
Makes file available to Drupal through the correct stream wrapper. Overrides FileSchemeHandlerInterface:: |
|
S3FileSchemeHandler:: |
public | function |
S3FileSchemeHandler constructor. Overrides PluginBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |