Skip to content

Commit

Permalink
[FEAT] Migrate from PageRenderer to AssetCollector for asset management
Browse files Browse the repository at this point in the history
Replaced PageRenderer with AssetCollector in MediaPlayerController.php for adding CSS and JavaScript assets -
Feature TYPO3 v10.3:
https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.3/Feature-90522-IntroduceAssetCollector.html#changelog-Feature-90522-IntroduceAssetCollector
  • Loading branch information
fschoelzel committed Dec 17, 2024
1 parent 71a590c commit 4847abd
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions Classes/Controller/MediaPlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Kitodo\Dlf\Controller;

use Kitodo\Dlf\Common\AbstractDocument;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;

Expand Down Expand Up @@ -53,7 +53,7 @@ public function mainAction(): void
return;
}

$this->addPlayerJS();
$this->addPlayerAssets();

$this->view->assign('video', $video);
}
Expand Down Expand Up @@ -228,6 +228,12 @@ protected function recurseChapters(array $logInfo, array &$outChapters)
}
}

/**
* Check if the given MIME type corresponds to a media file.
*
* @param string $mimeType The MIME type to check
* @return bool True if the MIME type corresponds to a media file, false otherwise
*/
protected function isMediaMime(string $mimeType)
{
return (
Expand All @@ -240,25 +246,34 @@ protected function isMediaMime(string $mimeType)
}

/**
* Adds Player javascript
* Adds Mediaplayer javascript and css assets
*
* @access protected
*
* @return void
*/
protected function addPlayerJS()
protected function addPlayerAssets(): void
{
// TODO: TYPO3 v10
// $assetCollector = GeneralUtility::makeInstance(AssetCollector::class);
// $assetCollector->addJavaScript('DlfMediaPlayer.js', 'EXT:dlf/Resources/Public/JavaScript/DlfMediaPlayer.js');
// $assetCollector->addStyleSheet('DlfMediaPlayer.css', 'EXT:dlf/Resources/Public/Css/DlfMediaPlayerStyles.css');

// TODO: Move to TypoScript
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addCssFile('EXT:dlf/Resources/Public/Css/DlfMediaPlayer.css');
$pageRenderer->addCssFile('EXT:dlf/Resources/Public/Css/DlfMediaVendor.css', 'stylesheet', 'all', '', true, false, '', /* excludeFromConcatenation= */true);
$pageRenderer->addCssFile('EXT:dlf/Resources/Public/Css/DlfMediaPlayerStyles.css');
$pageRenderer->addJsFooterFile('EXT:dlf/Resources/Public/JavaScript/DlfMediaPlayer.js');
$pageRenderer->addJsFooterFile('EXT:dlf/Resources/Public/JavaScript/DlfMediaVendor.js', 'text/javascript', true, false, '', /* excludeFromConcatenation= */true);
$assetCollector = GeneralUtility::makeInstance(AssetCollector::class);
$assetCollector->addStyleSheet(
'DlfMediaVendorCss',
'EXT:dlf/Resources/Public/Css/DlfMediaVendor.css',
['type' => 'text/css', 'media' => 'all']
);
$assetCollector->addStyleSheet(
'DlfMediaPlayerStylesCss',
'EXT:dlf/Resources/Public/Css/DlfMediaPlayerStyles.css',
['type' => 'text/css', 'media' => 'all']
);
$assetCollector->addJavaScript(
'DlfMediaPlayerJs',
'EXT:dlf/Resources/Public/JavaScript/DlfMediaPlayer.js',
['type' => 'text/javascript']
);
$assetCollector->addJavaScript(
'DlfMediaVendorJs',
'EXT:dlf/Resources/Public/JavaScript/DlfMediaVendor.js',
['type' => 'text/javascript']
);
}
}

0 comments on commit 4847abd

Please sign in to comment.