Skip to content

Commit

Permalink
Merge pull request #2 from IchHabRecht/add-typo3confvars-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabRecht authored Jun 19, 2018
2 parents 704ccd4 + 0bc79fa commit 2acb334
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 15 deletions.
55 changes: 47 additions & 8 deletions Classes/Resource/RemoteResourceCollectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
21 changes: 14 additions & 7 deletions Classes/Slot/ResourceFactorySlot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2acb334

Please sign in to comment.