You are here

class S3StorageHandlerModuleDependencyCollector in Acquia Content Hub 8.2

Subscribes to dependency collection to append module dependency information.

Hierarchy

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
acquia_contenthub.s3_file.dependency_collector in modules/acquia_contenthub_s3/acquia_contenthub_s3.services.yml
Drupal\acquia_contenthub_s3\EventSubscriber\DependencyCollector\S3StorageHandlerModuleDependencyCollector

File

modules/acquia_contenthub_s3/src/EventSubscriber/DependencyCollector/S3StorageHandlerModuleDependencyCollector.php, line 13

Namespace

Drupal\acquia_contenthub_s3\EventSubscriber\DependencyCollector
View 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

Namesort descending Modifiers Type Description Overrides
BaseDependencyCollector::getCalculator protected function Gets the dependency calculator.
BaseDependencyCollector::mergeDependencies protected function Properly adds dependencies and their modules to a wrapper object.
S3StorageHandlerModuleDependencyCollector::$moduleHandler protected property The module handler.
S3StorageHandlerModuleDependencyCollector::$requiredS3Modules protected property List of modules that implement AWS S3 storage handling.
S3StorageHandlerModuleDependencyCollector::getS3ModuleDependencies protected function Returns all the s3 module dependencies.
S3StorageHandlerModuleDependencyCollector::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
S3StorageHandlerModuleDependencyCollector::onCalculateDependencies public function Adds the accepted s3 modules to the module dependency list if applicable.
S3StorageHandlerModuleDependencyCollector::__construct public function S3FileDependencyCollector constructor.