From af77772a53b5d4818cf8498d2cc40e72a926e0f3 Mon Sep 17 00:00:00 2001 From: Alexander Stehlik Date: Mon, 3 Jul 2023 23:52:55 +0200 Subject: [PATCH] [TASK] Backport changes for TYPO3 11 --- .github/workflows/test.yml | 8 +-- Classes/Controller/MediaController.php | 4 +- Classes/Domain/Model/Media.php | 4 ++ .../TCA/Overrides/sys_file_reference.php | 20 +++---- .../tx_html5mediakit_domain_model_media.php | 53 ++++++++++++------- .../AbstractMediaControllerTestCase.php | 4 +- .../MediaController/RelatedTableTest.php | 8 +-- composer.json | 8 +-- ext_emconf.php | 4 +- ext_tables.php | 7 +++ 10 files changed, 74 insertions(+), 46 deletions(-) create mode 100644 ext_tables.php diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6a292a41..506ed882 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,13 +54,13 @@ jobs: with: php_version: "${{ env.MAIN_PHP_VERSION }}" - run: | - bash .Build/bin/t3_run_tests.sh -s cgl -n -p ${{ env.MAIN_PHP_VERSION }} + bash .Build/bin/t3_run_tests.sh -s cgl -n -p 8.1 "php-unit-tests": name: "PHP Unit tests" strategy: matrix: - php_version: ["8.1", "8.2"] + php_version: ["7.4", "8.2"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -107,7 +107,7 @@ jobs: name: "PHP linting" strategy: matrix: - php_version: ["8.1", "8.2"] + php_version: ["7.4", "8.0", "8.1", "8.2"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -191,4 +191,4 @@ jobs: - uses: shivammathur/setup-php@v2 with: php-version: "${{ env.MAIN_PHP_VERSION }}" - - run: php .Build/bin/typo3scan scan --target 12 . + - run: php .Build/bin/typo3scan scan --target 11 . diff --git a/Classes/Controller/MediaController.php b/Classes/Controller/MediaController.php index 746b5c68..0a522fab 100644 --- a/Classes/Controller/MediaController.php +++ b/Classes/Controller/MediaController.php @@ -54,7 +54,7 @@ public function renderMediaAction(): ResponseInterface $contentObject = $this->getCurrentContentObject(); try { - $uid = $contentObject->data['_LOCALIZED_UID'] ?? $contentObject->data['uid']; + $uid = (int)($contentObject->data['_LOCALIZED_UID'] ?? $contentObject->data['uid']); $media = $this->mediaRepository->findOneByContentElementUid($uid); } catch (MediaException $mediaException) { return $this->htmlResponse($this->translate('exception.' . $mediaException->getCode())); @@ -85,7 +85,7 @@ public function videoAction(Video $video): ResponseInterface private function getCurrentContentObject(): ContentObjectRenderer { - return $this->request->getAttribute('currentContentObject'); + return $this->configurationManager->getContentObject(); } private function renderMedia(Media $media): ResponseInterface diff --git a/Classes/Domain/Model/Media.php b/Classes/Domain/Model/Media.php index 88f634c1..b3069bc5 100644 --- a/Classes/Domain/Model/Media.php +++ b/Classes/Domain/Model/Media.php @@ -124,6 +124,10 @@ public function getParentTable(): string public function getTracks(): ObjectStorage { + if (!$this->tracks instanceof ObjectStorage) { + $this->tracks = new ObjectStorage(); + } + return $this->tracks; } diff --git a/Configuration/TCA/Overrides/sys_file_reference.php b/Configuration/TCA/Overrides/sys_file_reference.php index fd255b80..5a84c333 100644 --- a/Configuration/TCA/Overrides/sys_file_reference.php +++ b/Configuration/TCA/Overrides/sys_file_reference.php @@ -14,24 +14,24 @@ 'renderType' => 'selectSingle', 'items' => [ [ - 'label' => $lllPrefix . 'tx_html5mediakit_track_kind.I.subtitles', - 'value' => 'subtitles', + $lllPrefix . 'tx_html5mediakit_track_kind.I.subtitles', + 'subtitles', ], [ - 'label' => $lllPrefix . 'tx_html5mediakit_track_kind.I.captions', - 'value' => 'captions', + $lllPrefix . 'tx_html5mediakit_track_kind.I.captions', + 'captions', ], [ - 'label' => $lllPrefix . 'tx_html5mediakit_track_kind.I.descriptions', - 'value' => 'descriptions', + $lllPrefix . 'tx_html5mediakit_track_kind.I.descriptions', + 'descriptions', ], [ - 'label' => $lllPrefix . 'tx_html5mediakit_track_kind.I.chapters', - 'value' => 'chapters', + $lllPrefix . 'tx_html5mediakit_track_kind.I.chapters', + 'chapters', ], [ - 'label' => $lllPrefix . 'tx_html5mediakit_track_kind.I.metadata', - 'value' => 'metadata', + $lllPrefix . 'tx_html5mediakit_track_kind.I.metadata', + 'metadata', ], ], 'default' => 'subtitles', diff --git a/Configuration/TCA/tx_html5mediakit_domain_model_media.php b/Configuration/TCA/tx_html5mediakit_domain_model_media.php index 597a517c..47b9f8d9 100644 --- a/Configuration/TCA/tx_html5mediakit_domain_model_media.php +++ b/Configuration/TCA/tx_html5mediakit_domain_model_media.php @@ -4,17 +4,20 @@ use Sto\Html5mediakit\Domain\Model\Enumeration\MediaType; use TYPO3\CMS\Core\Resource\AbstractFile; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; $languagePrefix = 'LLL:EXT:html5mediakit/Resources/Private/Language/locallang_db.xlf:'; $languagePrefixColumn = $languagePrefix . 'tx_html5mediakit_domain_model_media.'; $languagePrefixCsh = 'LLL:EXT:html5mediakit/Resources/Private/Language/locallang_csh_media.xlf:'; $lllAddImageFileReference = 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference'; +/** @param array|string $allowedFileTypes */ $buildFileFieldConfig = function ( - string|array $allowedFileTypes, + string $fieldName, + $allowedFileTypes, int $maxitems = 1, string $showitem = '', - string $createNewRelationLinkTitle = '', + string $createNewRelationLinkTitle = '' ) use ( $languagePrefix ) { @@ -26,9 +29,15 @@ $createNewRelationLinkTitle = $languagePrefix . 'choose_file'; } + if (is_array($allowedFileTypes)) { + $allowedFileTypes = implode(',', $allowedFileTypes); + } + + if ($allowedFileTypes === 'common-image-types') { + $allowedFileTypes = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']; + } + $config = [ - 'type' => 'file', - 'allowed' => $allowedFileTypes, 'appearance' => [ 'showPossibleLocalizationRecords' => true, 'showAllLocalizationLink' => $allowsMultipleFiles, @@ -61,7 +70,11 @@ $config['maxitems'] = $maxitems; } - return $config; + return ExtensionManagementUtility::getFileFieldTCAConfig( + $fieldName, + $config, + $allowedFileTypes + ); }; return [ @@ -82,7 +95,6 @@ 'languageField' => 'sys_language_uid', 'transOrigPointerField' => 'l10n_parent', 'transOrigDiffSourceField' => 'l10n_diffsource', - 'security' => ['ignorePageTypeRestriction' => true], ], 'columns' => [ 'type' => [ @@ -93,12 +105,12 @@ 'renderType' => 'selectSingle', 'items' => [ [ - 'label' => $languagePrefixColumn . 'type.I.video', - 'value' => MediaType::VIDEO, + $languagePrefixColumn . 'type.I.video', + MediaType::VIDEO, ], [ - 'label' => $languagePrefixColumn . 'type.I.audio', - 'value' => MediaType::AUDIO, + $languagePrefixColumn . 'type.I.audio', + MediaType::AUDIO, ], ], 'default' => MediaType::VIDEO, @@ -110,6 +122,7 @@ 'label' => $languagePrefixColumn . 'tracks', 'description' => $languagePrefixCsh . 'tracks.description', 'config' => $buildFileFieldConfig( + 'tracks', ['vtt'], 0, 'tx_html5mediakit_track_kind, tx_html5mediakit_track_label, tx_html5mediakit_track_srclang', @@ -141,8 +154,8 @@ 'renderType' => 'selectSingle', 'items' => [ [ - 'label' => '', - 'value' => 0, + '', + 0, ], ], 'foreign_table' => 'tx_html5mediakit_domain_model_media', @@ -154,12 +167,13 @@ 'mp3' => [ 'label' => $languagePrefixColumn . 'mp3', 'description' => $languagePrefixCsh . 'mp3.description', - 'config' => $buildFileFieldConfig(['mp3']), + 'config' => $buildFileFieldConfig('mp3', ['mp3']), ], 'ogg' => [ 'label' => $languagePrefixColumn . 'ogg', 'description' => $languagePrefixCsh . 'ogg.description', 'config' => $buildFileFieldConfig( + 'ogg', [ 'ogg', 'ogx', @@ -169,18 +183,21 @@ 'h264' => [ 'label' => $languagePrefixColumn . 'h264', 'description' => $languagePrefixCsh . 'h264.description', - 'config' => $buildFileFieldConfig(['mp4']), + 'config' => $buildFileFieldConfig('h264', ['mp4']), ], 'ogv' => [ 'label' => $languagePrefixColumn . 'ogv', 'description' => $languagePrefixCsh . 'ogv.description', - 'config' => $buildFileFieldConfig(['ogv']), + 'config' => $buildFileFieldConfig('ogv', ['ogv']), ], 'poster' => [ 'label' => $languagePrefixColumn . 'poster', 'config' => $buildFileFieldConfig( - allowedFileTypes: 'common-image-types', - createNewRelationLinkTitle: $lllAddImageFileReference + 'poster', + 'common-image-types', + 1, + '', + $lllAddImageFileReference ), ], 'sys_language_uid' => [ @@ -191,7 +208,7 @@ 'web_m' => [ 'label' => $languagePrefixColumn . 'web_m', 'description' => $languagePrefixCsh . 'web_m.description', - 'config' => $buildFileFieldConfig(['webm']), + 'config' => $buildFileFieldConfig('web_m', ['webm']), ], 'content_element' => [ 'config' => ['type' => 'passthrough'], diff --git a/Tests/Functional/Controller/MediaController/AbstractMediaControllerTestCase.php b/Tests/Functional/Controller/MediaController/AbstractMediaControllerTestCase.php index 27c8af0a..08ece286 100644 --- a/Tests/Functional/Controller/MediaController/AbstractMediaControllerTestCase.php +++ b/Tests/Functional/Controller/MediaController/AbstractMediaControllerTestCase.php @@ -26,9 +26,9 @@ abstract class AbstractMediaControllerTestCase extends FunctionalTestCase { protected const FIXTURES_PATH = 'EXT:html5mediakit/Tests/Functional/Fixtures'; - protected array $coreExtensionsToLoad = ['fluid_styled_content']; + protected $coreExtensionsToLoad = ['fluid_styled_content']; - protected array $testExtensionsToLoad = ['typo3conf/ext/html5mediakit']; + protected $testExtensionsToLoad = ['typo3conf/ext/html5mediakit']; protected array $typoscriptConstantFiles = [ 'EXT:fluid_styled_content/Configuration/TypoScript/constants.typoscript', diff --git a/Tests/Functional/Controller/MediaController/RelatedTableTest.php b/Tests/Functional/Controller/MediaController/RelatedTableTest.php index 88089989..a14580dc 100644 --- a/Tests/Functional/Controller/MediaController/RelatedTableTest.php +++ b/Tests/Functional/Controller/MediaController/RelatedTableTest.php @@ -7,6 +7,7 @@ use Sto\Html5mediakit\Domain\Repository\MediaRepository; use Sto\Html5mediakit\Tests\Unit\Controller\MediaControllerMock; use TYPO3\CMS\Core\Http\ServerRequest; +use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Http\ForwardResponse; use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters; use TYPO3\CMS\Extbase\Mvc\Request; @@ -26,13 +27,12 @@ public function testMediaControllerShowsVideo(): void 'parent_record' => 23, ]; - $baseRequest = (new ServerRequest()) - ->withAttribute('extbase', new ExtbaseRequestParameters()) - ->withAttribute('currentContentObject', $contentObject); + $configurationManagerMock = $this->createMock(ConfigurationManagerInterface::class); + $configurationManagerMock->method('getContentObject')->willReturn($contentObject); $controller = new MediaControllerMock(); $controller->injectMediaRepository($container->get(MediaRepository::class)); - $controller->setRequest(new Request($baseRequest)); + $controller->injectConfigurationManager($configurationManagerMock); $response = $controller->renderMediaForRelatedTableAction(); diff --git a/composer.json b/composer.json index dbb21128..9ad977eb 100644 --- a/composer.json +++ b/composer.json @@ -4,19 +4,19 @@ "license": "GPL-3.0-or-later", "type": "typo3-cms-extension", "require": { - "php": "^8.1", - "typo3/cms-core": "^12.4", + "php": "^7.4 || ^8.0", + "typo3/cms-core": "^11.5", "typo3/cms-extbase": "*", "typo3/cms-frontend": "*" }, "require-dev": { "de-swebhosting/php-codestyle": "^5.0", - "de-swebhosting/typo3-extension-buildtools": "dev-TYPO3_12", + "de-swebhosting/typo3-extension-buildtools": "dev-TYPO3_11", "ergebnis/composer-normalize": "^2.28", "friendsofphp/php-cs-fixer": "^3.14", "michielroos/typo3scan": "^1.7", "squizlabs/php_codesniffer": "^3.7", - "symfony/dom-crawler": "^6.3", + "symfony/dom-crawler": "^5.4", "typo3/cms-fluid-styled-content": "*" }, "replace": { diff --git a/ext_emconf.php b/ext_emconf.php index ca01a881..c5c03736 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -12,10 +12,10 @@ 'author' => 'Alexander Stehlik', 'author_email' => 'alexander.stehlik.deleteme@gmail.com', 'author_company' => '', - 'version' => '12.0.0', + 'version' => '11.1.0', 'constraints' => [ 'depends' => [ - 'typo3' => '12.4.0-12.4.99', + 'typo3' => '11.5.0-11.5.99', 'extbase' => '', ], 'conflicts' => [], diff --git a/ext_tables.php b/ext_tables.php new file mode 100644 index 00000000..d59a4f4a --- /dev/null +++ b/ext_tables.php @@ -0,0 +1,7 @@ +