Skip to content

Commit

Permalink
[FEATURE] Render default thumbnail if online media helper can not fet…
Browse files Browse the repository at this point in the history
…ch one

The default thumbnail is customizable using TypoScript. Read the docs for more information.
  • Loading branch information
pascal20997 committed Jun 23, 2020
1 parent b181d72 commit 7ac253a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Classes/ViewHelpers/VideoPreviewImageViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

Expand Down Expand Up @@ -70,11 +72,32 @@ public static function renderStatic(
if (!is_dir($publicDirectory)) {
GeneralUtility::mkdir_deep($publicDirectory);
}
copy($privateFile, $publicFile);
if (is_file($privateFile)) {
copy($privateFile, $publicFile);
} else {
// sometimes OnlineMediaHelperInterface::getPreviewImage() returns a file that does not exist!
$publicFile = static::getDefaultThumbnailFile();
}
}
} else {
$publicFile = '';
}
return $publicFile;
}

protected static function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}

protected static function getDefaultThumbnailFile(): string
{
$filename = static::getTypoScriptFrontendController()->tmpl->setup['lib.']['video_shariff.']['defaultThumbnail'];
if (strpos($filename, 'EXT:') === 0) {
$file = GeneralUtility::getFileAbsFileName($filename);
} else {
$file = PathUtility::getAbsoluteWebPath($filename);
}
return $file;
}
}
4 changes: 4 additions & 0 deletions Configuration/TypoScript/constants.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib.video_shariff {
# cat=basic/file/1; type=string; label=Default thumbnail when no video specific thumbnail can be fetched
defaultThumbnail = EXT:video_shariff/Resources/Public/Images/DefaultThumbnail.jpg
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ lib.contentElement {
}
}

lib.video_shariff {
defaultThumbnail = {$lib.video_shariff.defaultThumbnail}
}

page.includeCSS.video_shariff = EXT:video_shariff/Resources/Public/Css/VideoShariff.min.css
page.includeJSFooterlibs.video_shariff = EXT:video_shariff/Resources/Public/JavaScript/VideoShariff.min.js
22 changes: 22 additions & 0 deletions Documentation/Administrator/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,25 @@ You can override the default preview image text and adding new languages via Typ
plugin.tx_videoshariff._LOCAL_LANG.default.preview\.text = I am a custom preview text...
plugin.tx_videoshariff._LOCAL_LANG.de.preview\.text = Ich bin ein angepasster Vorschautext...
Use a custom default thumbnail
------------------------------

The default thumbnail is rendered when no video specific thumbnail can be fetched. You can use your own
thumbnail using the constant editor or TypoScript.

Using constant editor
++++++++++++++++++++++

Template > Constant Editor > Basic

.. figure:: ../Images/CustomThumbnailConstantEditor.png
:width: 300px
:alt: Constant editor

Using TypoScript setup or constants
+++++++++++++++++++++++++++++++++++

.. code-block:: typoscript
lib.video_shariff.defaultThumbnail = fileadmin/myCustomThumbnail.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Public/Images/DefaultThumbnail.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7ac253a

Please sign in to comment.