Skip to content

Commit

Permalink
Merge pull request #10 from kandoh-gmbh/release/v12
Browse files Browse the repository at this point in the history
[TASK] Remove EXT:vhs dependency
  • Loading branch information
svewap authored Aug 12, 2024
2 parents 238b2a1 + 9185994 commit dfa2643
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 9 deletions.
67 changes: 67 additions & 0 deletions Classes/ViewHelpers/AspectRatioClassViewHelper.php
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;
}
}
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>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers" data-namespace-typo3-fluid="true">
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<figure class="video ">
<div class="player-container tx-videos__player">
<f:render partial="Media/Rendering/Video" arguments="{data: data, file: file, dimensions: dimensions, settings: settings}" />
Expand Down

0 comments on commit dfa2643

Please sign in to comment.