Commit 2007789b authored by Tomas Norre Mikkelsen's avatar Tomas Norre Mikkelsen

Merge branch '250-ext_icon-svg-should-be-preferred' into 'develop'

Adds order of showing extension icons in frontend

Closes #250

See merge request !229
parents a229716d 3d6c5a16
Pipeline #2369 passed with stages
in 2 minutes and 22 seconds
......@@ -165,26 +165,25 @@ class TerIndexer extends \ApacheSolrForTypo3\Solr\IndexQueue\Indexer
*/
protected function getExtensionIcon($extensionKey, $extensionVersion)
{
// check if there is a gif or a png icon or if there is no icon
$iconFilePng = $this->generateIconFileName(
$extensionKey,
$extensionVersion,
'png'
);
$iconFileGif = $this->generateIconFileName(
$extensionKey,
$extensionVersion,
$fileTypesToCheck = [
'svg',
'png',
'gif'
);
];
$iconPath = 'fileadmin/ter/';
$icon = '';
if (file_exists(PATH_site.$iconPath.$iconFilePng)) {
$icon = \T3o\TerFe2\Utility\File::getRelativeUrlFromAbsolutePath($iconPath.$iconFilePng);
} elseif (file_exists(PATH_site.$iconPath.$iconFileGif)) {
$icon = \T3o\TerFe2\Utility\File::getRelativeUrlFromAbsolutePath($iconPath.$iconFileGif);
foreach ($fileTypesToCheck as $fileType) {
$iconFile = $this->generateIconFileName(
$extensionKey,
$extensionVersion,
$fileType
);
if (file_exists(PATH_site . $iconPath . $iconFile)) {
$icon = \T3o\TerFe2\Utility\File::getRelativeUrlFromAbsolutePath($iconPath . $iconFile);
break;
}
}
return $icon;
......
......@@ -42,6 +42,15 @@ class ExtensionIconViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractT
*/
protected $providerManager;
/**
* @var array
*/
protected $fileIconOrder = [
'svg',
'png',
'gif'
];
/**
* Initialize arguments
*
......@@ -59,10 +68,9 @@ class ExtensionIconViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractT
* Renders an extension icon for given version object
*
* @param \T3o\TerFe2\Domain\Model\Version $version Version object
* @param string $fileType File type
* @return string Rendered image tag
*/
public function render(\T3o\TerFe2\Domain\Model\Version $version = null, $fileType = 'png')
public function render(\T3o\TerFe2\Domain\Model\Version $version = null)
{
if ($version === null) {
$version = $this->renderChildren();
......@@ -71,9 +79,11 @@ class ExtensionIconViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractT
$imageUrl = '';
$provider = $version->getExtensionProvider();
if (!empty($provider)) {
$imageUrl = $this->providerManager->getProvider($provider)->getIconUrl($version, $fileType);
if (empty($imageUrl) || !file_exists(\T3o\TerFe2\Utility\File::getAbsolutePathFromUrl($imageUrl))) {
$imageUrl = $this->providerManager->getProvider($provider)->getIconUrl($version, 'gif');
foreach ($this->fileIconOrder as $fileType) {
$imageUrl = $this->providerManager->getProvider($provider)->getIconUrl($version, $fileType);
if (!empty($imageUrl) && file_exists(\T3o\TerFe2\Utility\File::getAbsolutePathFromUrl($imageUrl))) {
break;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment