Skip to content

Commit

Permalink
[BUGFIX] Detect core media fields correctly in v12
Browse files Browse the repository at this point in the history
Fixes: #588
(cherry picked from commit 6fe901b)
  • Loading branch information
nhovratov committed Sep 11, 2023
1 parent d12bcff commit 769e953
Show file tree
Hide file tree
Showing 3 changed files with 571 additions and 473 deletions.
7 changes: 6 additions & 1 deletion Build/phpstan/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ parameters:
count: 1
path: ../../Classes/Utility/FieldTypeUtility.php

-
message: "#^Method MASK\\\\Mask\\\\Utility\\\\FieldTypeUtility\\:\\:isMediaType\\(\\) has parameter \\$tca with no value type specified in iterable type array\\.$#"
count: 1
path: ../../Classes/Utility/FieldTypeUtility.php

-
message: "#^Method MASK\\\\Mask\\\\Utility\\\\TcaConverter\\:\\:convertFlatTcaToArray\\(\\) has parameter \\$tca with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -976,7 +981,7 @@ parameters:
path: ../../Tests/Unit/Definition/TableDefinitionCollectionTest.php

-
message: "#^Method MASK\\\\Mask\\\\Tests\\\\Unit\\\\Definition\\\\TableDefinitionCollectionTest\\:\\:getFormTypeDataProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
message: "#^Method MASK\\\\Mask\\\\Tests\\\\Unit\\\\Definition\\\\TableDefinitionCollectionTest\\:\\:getFormTypeDataProvider\\(\\) return type has no value type specified in iterable type iterable\\.$#"
count: 1
path: ../../Tests/Unit/Definition/TableDefinitionCollectionTest.php

Expand Down
30 changes: 24 additions & 6 deletions Classes/Utility/FieldTypeUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use InvalidArgumentException;
use MASK\Mask\Enumeration\FieldType;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry;
use TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException;
use TYPO3\CMS\Core\Utility\GeneralUtility as CoreGeneralUtility;
Expand Down Expand Up @@ -74,12 +75,7 @@ public static function getFieldType(array $tca, string $fieldKey): string
return FieldType::TEXT;
case 'inline':
if (($tca['config']['foreign_table'] ?? '') === 'sys_file_reference') {
// Check if the allowed list contains online media types.
$allowedList = $tca['config']['overrideChildTca']['columns']['uid_local']['config']['appearance']['elementBrowserAllowed'] ?? '';
$allowedList = CoreGeneralUtility::trimExplode(',', $allowedList, true);
$onlineMediaHelperRegistry = CoreGeneralUtility::makeInstance(OnlineMediaHelperRegistry::class);
$onlineMediaTypes = $onlineMediaHelperRegistry->getSupportedFileExtensions();
if (!empty(array_intersect($allowedList, $onlineMediaTypes))) {
if (self::isMediaType($tca)) {
return FieldType::MEDIA;
}
return FieldType::FILE;
Expand Down Expand Up @@ -115,6 +111,11 @@ public static function getFieldType(array $tca, string $fieldKey): string
return FieldType::GROUP;
case 'folder':
return FieldType::FOLDER;
case 'file':
if (self::isMediaType($tca)) {
return FieldType::MEDIA;
}
return FieldType::FILE;
default:
// Check if fake tca type is valid.
try {
Expand All @@ -124,4 +125,21 @@ public static function getFieldType(array $tca, string $fieldKey): string
}
}
}

protected static function isMediaType(array $tca): bool
{
// Check if the allowed list contains online media types.
if ((new Typo3Version())->getVersion() < 12) {
$allowedList = $tca['config']['overrideChildTca']['columns']['uid_local']['config']['appearance']['elementBrowserAllowed'] ?? '';
} else {
$allowedList = $tca['config']['allowed'] ?? '';
}
$allowedList = CoreGeneralUtility::trimExplode(',', $allowedList, true);
$onlineMediaHelperRegistry = CoreGeneralUtility::makeInstance(OnlineMediaHelperRegistry::class);
$onlineMediaTypes = $onlineMediaHelperRegistry->getSupportedFileExtensions();
if (!empty(array_intersect($allowedList, $onlineMediaTypes))) {
return true;
}
return false;
}
}
Loading

0 comments on commit 769e953

Please sign in to comment.