diff --git a/Classes/Resource/RemoteResourceCollectionFactory.php b/Classes/Resource/RemoteResourceCollectionFactory.php index 43aa663..52d1c23 100644 --- a/Classes/Resource/RemoteResourceCollectionFactory.php +++ b/Classes/Resource/RemoteResourceCollectionFactory.php @@ -22,25 +22,24 @@ class RemoteResourceCollectionFactory { /** - * @param string $configuration + * @param array $configuration + * @throws \RuntimeException * @return RemoteResourceCollection */ - public static function createRemoteResourceCollectionFromConfiguration($configuration) + public static function createRemoteResourceCollectionFromConfiguration(array $configuration) { $remoteResources = []; - $resourcesConfiguration = GeneralUtility::xml2array($configuration); - - foreach ((array)$resourcesConfiguration['data']['sDEF']['lDEF']['resources']['el'] as $resource) { + foreach ($configuration as $key => $resource) { if (empty($resource)) { continue; } - $key = key($resource); - switch ($key) { case 'domain': - $remoteResources[] = GeneralUtility::makeInstance(DomainResource::class, $resource['domain']['el']['domain']['vDEF']); + foreach ($resource as $domain) { + $remoteResources[] = GeneralUtility::makeInstance(DomainResource::class, $domain); + } break; case 'sys_domain': $domainResourceRepository = GeneralUtility::makeInstance(DomainResourceRepository::class); @@ -56,4 +55,44 @@ public static function createRemoteResourceCollectionFromConfiguration($configur return GeneralUtility::makeInstance(RemoteResourceCollection::class, $remoteResources); } + + /** + * @param string $flexForm + * @throws \RuntimeException + * @return RemoteResourceCollection + */ + public static function createRemoteResourceCollectionFromFlexForm($flexForm) + { + $configuration = []; + + $resourcesConfiguration = GeneralUtility::xml2array($flexForm); + + foreach ((array)$resourcesConfiguration['data']['sDEF']['lDEF']['resources']['el'] as $resource) { + if (empty($resource)) { + continue; + } + + $key = key($resource); + + switch ($key) { + case 'domain': + if (empty($configuration[$key])) { + $configuration[$key] = []; + } + $configuration[$key] = array_merge( + $configuration[$key], + [$resource['domain']['el']['domain']['vDEF']] + ); + break; + case 'sys_domain': + case 'placeholder': + $configuration[$key] = true; + break; + default: + throw new \RuntimeException('Unexpected File Fill Resource configuration "' . $key . '"', 1528326468); + } + } + + return self::createRemoteResourceCollectionFromConfiguration($configuration); + } } diff --git a/Classes/Slot/ResourceFactorySlot.php b/Classes/Slot/ResourceFactorySlot.php index b1db78e..e1c2582 100644 --- a/Classes/Slot/ResourceFactorySlot.php +++ b/Classes/Slot/ResourceFactorySlot.php @@ -26,10 +26,11 @@ class ResourceFactorySlot public function initializeResourceStorage(ResourceFactory $resourceFactory, ResourceStorage $resourceStorage) { $storageRecord = $resourceStorage->getStorageRecord(); - if ($storageRecord['driver'] !== 'Local' - || empty($storageRecord['tx_filefill_enable']) - || empty($storageRecord['tx_filefill_resources']) - ) { + $isLocalDriver = $storageRecord['driver'] === 'Local'; + $isRecordEnabled = !empty($storageRecord['tx_filefill_enable']) && !empty($storageRecord['tx_filefill_resources']); + $isStorageConfigured = !empty($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][$resourceStorage->getUid()]); + + if (!$isLocalDriver || (!$isRecordEnabled && !$isStorageConfigured)) { return; } @@ -38,9 +39,15 @@ public function initializeResourceStorage(ResourceFactory $resourceFactory, Reso }, null, ResourceStorage::class); $originalDriverObject = $closure(); - $remoteResourceCollection = RemoteResourceCollectionFactory::createRemoteResourceCollectionFromConfiguration( - $storageRecord['tx_filefill_resources'] - ); + if ($isRecordEnabled) { + $remoteResourceCollection = RemoteResourceCollectionFactory::createRemoteResourceCollectionFromFlexForm( + $storageRecord['tx_filefill_resources'] + ); + } else { + $remoteResourceCollection = RemoteResourceCollectionFactory::createRemoteResourceCollectionFromConfiguration( + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][$resourceStorage->getUid()] + ); + } $driverObject = GeneralUtility::makeInstance( FileFillDriver::class, diff --git a/README.md b/README.md index 8dfe67b..06bf080 100644 --- a/README.md +++ b/README.md @@ -25,12 +25,32 @@ You only need to configure one or more existing "File Storage" records *Prerequisite: Only storages with a "Local filesystem" driver are currently supported.* +### Database record configuration + - go to the root of your TYPO3 page tree (id=0) - change to the list module (Web -> List on the left side) - find the "File Storage" section and edit a record - change to the tab "File Fill" and select the enable checkbox - define the resource chain that should be used to fetch missing files +### TYPO3_CONF_VARS configuration + +- given a file storage with uid 1, the configuration might look like this + +```php +$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][1] = [ + 'domain' => [ + 'https://example.com', + 'https://example.org', + ], + 'sys_domain' => true, + 'placeholder' => true, +]; +``` + +- you don't need to configure resources that you don't want to use +- the ordering in your configuration defines the ordering of processing + ## Resources Resources define the places (url / services) were filefill tries to fetch missing files from. You can use multiple