Skip to content
Snippets Groups Projects
Commit ff194b57 authored by Johannes Kreiner's avatar Johannes Kreiner
Browse files

[BUGFIX] Fix url parameter handover issues

parent ea7af46a
No related branches found
No related tags found
No related merge requests found
<?php
namespace SGalinski\SgVimeo\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the AY project. The AY project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* View helper that takes a URL and adds the parameters respecting the separator
*
* Example:
* {namespace vi=SGalinski\SgVimeo\ViewHelpers}
* <vi:urlWithQueryParameters url="https://player.vimeo.com/video/123?h=xyz" parameters="?origin=https://demo.sgalinski.de" />
* Result: https://player.vimeo.com/video/123?h=xyz&origin=https://demo.sgalinski.de
*/
class UrlWithQueryParametersViewHelper extends AbstractViewHelper {
/**
* Register the ViewHelper arguments
*/
public function initializeArguments(): void {
parent::initializeArguments();
$this->registerArgument('url', 'string', 'The url to add the query parameters to', TRUE);
$this->registerArgument('parameters', 'string', 'The query parameters to add', FALSE, '');
}
/**
* Returns the url with the added query parameters
*
* @return string
*/
public function render(): string {
$url = $this->arguments['url'];
$additionalUrlParameters = $this->arguments['parameters'];
if ($additionalUrlParameters === '') {
return $url;
}
$beginsWithQuestionMark = $additionalUrlParameters[0] === '?';
$beginsWithAmpersand = $additionalUrlParameters[0] === '&';
if ($beginsWithQuestionMark || $beginsWithAmpersand) {
$additionalUrlParameters = substr($additionalUrlParameters, 1);
}
return strpos($url, '?') !== FALSE
? $url . '&' . $additionalUrlParameters
: $url . '?' . $additionalUrlParameters;
}
}
......@@ -72,3 +72,7 @@ If the `?disableVimeoCache=1` parameter is added to the URL, this cache will be
### .htaccess
Requires `img-src https://i.vimeocdn.com;`, `script-src https://player.vimeo.com;` and `connect-src https://cdn.plyr.io;`.
### Known issues
- Additional URL parameters won't get passed to the iframe inside the lightbox, this is seemingly caused by Plyr's integration of the Vimeo API
- Workaround: disable the lightbox for your Vimeo video
{namespace sg=SGalinski\ProjectTheme\ViewHelpers}
{namespace vi=SGalinski\SgVimeo\ViewHelpers}
<f:layout name="Default"/>
......@@ -125,11 +126,12 @@
<f:section name="vimeoItem">
<f:variable name="urlParameters">{f:if(condition: '{settings.urlParameters}', then: '{settings.urlParameters}', else: '{settings.globalUrlParameters}')}</f:variable>
<f:variable name="feedItemUrl">{f:if(condition: '{feedItem.embedLink}', then: '{feedItem.embedLink}', else: '{feedItem.link}')}{urlParameters}</f:variable>
<f:variable name="feedItemUrl"><vi:urlWithQueryParameters url="{f:if(condition: '{feedItem.embedLink}', then: '{feedItem.embedLink}', else: '{feedItem.link}')}" parameters="{urlParameters}" /></f:variable>
<div class="sg-video__item">
<a class="sg-video__image-container sg-vimeo-item" href="{feedItemUrl}" target="_blank"
data-disable-lightbox="{settings.disableLightbox}"
data-disable-lightbox-mobile="{settings.disableLightboxMobile}">
data-disable-lightbox-mobile="{settings.disableLightboxMobile}"
data-additional-url-parameters="{urlParameters}">
<f:if condition="{feedItem.thumbnail}">
<f:then>
<img class="sg-video__image" src="{feedItem.thumbnail}" alt="{feedItem.name}" loading="lazy"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment