From 9de20cd66bf1f9898eb761051d8ba85ab904624a Mon Sep 17 00:00:00 2001 From: Moritz Ngo Date: Mon, 12 Aug 2024 10:56:52 +0200 Subject: [PATCH 1/2] [TASK] Remove EXT:vhs dependency --- .../AspectRatioClassViewHelper.php | 67 +++++++++++++++++++ .../Media/Rendering/Video.html | 15 +++-- .../Media/Type/Video.html | 2 +- 3 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 Classes/ViewHelpers/AspectRatioClassViewHelper.php diff --git a/Classes/ViewHelpers/AspectRatioClassViewHelper.php b/Classes/ViewHelpers/AspectRatioClassViewHelper.php new file mode 100644 index 0000000..5cfaab5 --- /dev/null +++ b/Classes/ViewHelpers/AspectRatioClassViewHelper.php @@ -0,0 +1,67 @@ +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; + } +} diff --git a/Resources/Private/Partials/fluid_styled_content/Media/Rendering/Video.html b/Resources/Private/Partials/fluid_styled_content/Media/Rendering/Video.html index cc69a26..a37fcbd 100644 --- a/Resources/Private/Partials/fluid_styled_content/Media/Rendering/Video.html +++ b/Resources/Private/Partials/fluid_styled_content/Media/Rendering/Video.html @@ -1,9 +1,14 @@ - - - - - + +