class S3StorageHandlerModuleDependencyCollector in Acquia Content Hub 8.2
Subscribes to dependency collection to append module dependency information.
Hierarchy
- class \Drupal\depcalc\EventSubscriber\DependencyCollector\BaseDependencyCollector implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\acquia_contenthub_s3\EventSubscriber\DependencyCollector\S3StorageHandlerModuleDependencyCollector
Expanded class hierarchy of S3StorageHandlerModuleDependencyCollector
1 string reference to 'S3StorageHandlerModuleDependencyCollector'
- acquia_contenthub_s3.services.yml in modules/
acquia_contenthub_s3/ acquia_contenthub_s3.services.yml - modules/acquia_contenthub_s3/acquia_contenthub_s3.services.yml
1 service uses S3StorageHandlerModuleDependencyCollector
File
- modules/
acquia_contenthub_s3/ src/ EventSubscriber/ DependencyCollector/ S3StorageHandlerModuleDependencyCollector.php, line 13
Namespace
Drupal\acquia_contenthub_s3\EventSubscriber\DependencyCollectorView source
class S3StorageHandlerModuleDependencyCollector extends BaseDependencyCollector {
/**
* List of modules that implement AWS S3 storage handling.
*
* @var string[]
*/
protected $requiredS3Modules = [
's3fs',
];
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* S3FileDependencyCollector constructor.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler service.
*/
public function __construct(ModuleHandlerInterface $moduleHandler) {
$this->moduleHandler = $moduleHandler;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[DependencyCalculatorEvents::CALCULATE_DEPENDENCIES][] = [
'onCalculateDependencies',
];
return $events;
}
/**
* Adds the accepted s3 modules to the module dependency list if applicable.
*
* @param \Drupal\depcalc\Event\CalculateEntityDependenciesEvent $event
* The dependency calculation event.
*/
public function onCalculateDependencies(CalculateEntityDependenciesEvent $event) {
/** @var \Drupal\field\FieldStorageConfigInterface $entity */
$entity = $event
->getEntity();
if ($entity
->getEntityTypeId() !== 'field_storage_config') {
return;
}
$uri_scheme = $entity
->getSetting('uri_scheme');
if (!$uri_scheme || $uri_scheme !== 's3') {
return;
}
$modules = $this
->getS3ModuleDependencies();
if (empty($modules)) {
return;
}
$modules = array_merge($event
->getModuleDependencies(), $modules);
$event
->setModuleDependencies($modules);
}
/**
* Returns all the s3 module dependencies.
*
* @return array
* Array of required S3 modules.
*/
protected function getS3ModuleDependencies() : array {
$modules = [];
foreach ($this->requiredS3Modules as $module) {
if (!$this->moduleHandler
->moduleExists($module)) {
continue;
}
$modules[] = $module;
}
return $modules;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BaseDependencyCollector:: |
protected | function | Gets the dependency calculator. | |
BaseDependencyCollector:: |
protected | function | Properly adds dependencies and their modules to a wrapper object. | |
S3StorageHandlerModuleDependencyCollector:: |
protected | property | The module handler. | |
S3StorageHandlerModuleDependencyCollector:: |
protected | property | List of modules that implement AWS S3 storage handling. | |
S3StorageHandlerModuleDependencyCollector:: |
protected | function | Returns all the s3 module dependencies. | |
S3StorageHandlerModuleDependencyCollector:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
S3StorageHandlerModuleDependencyCollector:: |
public | function | Adds the accepted s3 modules to the module dependency list if applicable. | |
S3StorageHandlerModuleDependencyCollector:: |
public | function | S3FileDependencyCollector constructor. |