-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from kandoh-gmbh/release/v12
[TASK] Remove EXT:vhs dependency
- Loading branch information
Showing
3 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the "videos" Extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace WapplerSystems\Videos\ViewHelpers; | ||
|
||
use TYPO3\CMS\Core\Resource\FileInterface; | ||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; | ||
|
||
/** | ||
* Class AspectRatioClassViewHelper | ||
* | ||
* @phpstan-type ArgumentsArray array{ | ||
* aspectRatio: FileInterface|string|null, | ||
* default: string|null | ||
* } | ||
*/ | ||
class AspectRatioClassViewHelper extends AbstractViewHelper | ||
{ | ||
#[\Override] | ||
public function initializeArguments(): void | ||
{ | ||
parent::initializeArguments(); | ||
|
||
$this->registerArgument('aspectRatio', 'mixed', 'The desired aspect ratio, can either be a FileInterface instance or an string. If omitted, $renderChildrenClosure() will be executed to be used for inline notation.', false); | ||
$this->registerArgument('default', 'string', 'If no valid aspectRatio is given, this value will be used.', false); | ||
} | ||
|
||
/** | ||
* @param ArgumentsArray $arguments | ||
*/ | ||
public static function renderStatic( | ||
array $arguments, | ||
\Closure $renderChildrenClosure, | ||
RenderingContextInterface $renderingContext | ||
): string { | ||
$defaultValue = (string)($arguments['default'] ?? '16:9'); | ||
$aspectRatio = $arguments['aspectRatio'] ?? $renderChildrenClosure(); | ||
|
||
// First check if the given aspectRatio argument is an file interface. | ||
// If so, read the "aspect_ratio" property from it | ||
if ( | ||
$aspectRatio instanceof FileInterface | ||
&& $aspectRatio->hasProperty('aspect_ratio') | ||
) { | ||
$aspectRatio = $aspectRatio->getProperty('aspect_ratio'); | ||
} | ||
|
||
// If the given aspectRatio argument is not a string or not set, use the default value | ||
if (! is_string($aspectRatio) || empty($aspectRatio)) { | ||
$aspectRatio = $defaultValue; | ||
} | ||
|
||
// Now it's time to replace the colon with a minus, so it'll be compatible with VideoJS | ||
$aspectRatio = str_replace(':', '-', $aspectRatio); | ||
|
||
// Last but not least, add the VideoJs prefix | ||
return 'vjs-' . $aspectRatio; | ||
} | ||
} |
21 changes: 13 additions & 8 deletions
21
Resources/Private/Partials/fluid_styled_content/Media/Rendering/Video.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> | ||
|
||
|
||
<f:media id="video{data.uid}" class="video-js vjs-big-play-centered vjs-{f:if(condition:file.properties.aspect_ratio,then:'{file.properties.aspect_ratio -> v:format.replace(substring:\':\',replacement:\'-\')}',else:'16-9')} " file="{file}" width="{dimensions.width}" height="{dimensions.height}" alt="{file.alternative}" title="{file.title}" /> | ||
|
||
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:videos="http://typo3.org/ns/WapplerSystems/Videos/ViewHelpers" data-namespace-typo3-fluid="true"> | ||
|
||
<f:media | ||
id="video{file.uid}" | ||
class="video-js vjs-big-play-centered {file -> videos:aspectRatioClass()}" | ||
file="{file}" | ||
width="{dimensions.width}" | ||
height="{dimensions.height}" | ||
alt="{file.alternative}" | ||
title="{file.title}" | ||
/> | ||
<script> | ||
var player{data.uid} = videojs('video{data.uid}'); | ||
player{data.uid}.markers(); | ||
player{data.uid}.markersUi(); | ||
var player{file.uid} = videojs('video{file.uid}'); | ||
player{file.uid}.markers(); | ||
player{file.uid}.markersUi(); | ||
</script> | ||
|
||
</html> |
2 changes: 1 addition & 1 deletion
2
Resources/Private/Partials/fluid_styled_content/Media/Type/Video.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters