Skip to content

Commit

Permalink
Merge pull request #304 from andersundsehr/feature/allow-override-of-…
Browse files Browse the repository at this point in the history
…ext-status-webp

[FEATURE] allow override of bootstrap.extconf.webp typoscript constants
  • Loading branch information
t3solution authored Apr 3, 2023
2 parents 8a02bbd + 18aead6 commit 3b3c1e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
14 changes: 12 additions & 2 deletions Classes/Utility/ResponsiveImagesUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
use TYPO3\CMS\Core\Imaging\ImageManipulation\Area;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
use TYPO3\CMS\Extbase\Service\ImageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -27,6 +28,13 @@ class ResponsiveImagesUtility implements SingletonInterface
*/
protected $imageService;

/**
* Configuration Manager
*
* @var ConfigurationManager
*/
protected $configurationManager;

/**
* Default media breakpoint configuration
*
Expand All @@ -42,9 +50,10 @@ class ResponsiveImagesUtility implements SingletonInterface
/**
* @param ImageService $imageService
*/
public function __construct(ImageService $imageService)
public function __construct(ImageService $imageService, ConfigurationManager $configurationManager)
{
$this->imageService = $imageService;
$this->configurationManager = $configurationManager;
}


Expand Down Expand Up @@ -85,7 +94,8 @@ public function createPictureTag(
$tag = $tag ?: GeneralUtility::makeInstance(TagBuilder::class, 'picture');
$fallbackTag = $fallbackTag ?: GeneralUtility::makeInstance(TagBuilder::class, 'img');

$webpIsLoaded = ExtensionManagementUtility::isLoaded('webp');
$settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
$webpIsLoaded = (bool)$settings['page.']['10.']['settings.']['webp'];

// Deal with file formats that can't be cropped separately
if ($this->hasIgnoredFileExtension($originalImage, $ignoreFileExtensions)) {
Expand Down
17 changes: 16 additions & 1 deletion Classes/ViewHelpers/MediaViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;

/*
* This file is part of the TYPO3 extension t3sbootstrap.
Expand All @@ -25,6 +26,11 @@ class MediaViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\MediaViewHelper
*/
protected $responsiveImagesUtility;

/**
* @var ConfigurationManager
*/
protected $configurationManager;

/**
* @param ResponsiveImagesUtility $responsiveImagesUtility
*/
Expand All @@ -33,6 +39,14 @@ public function injectResponsiveImagesUtility(ResponsiveImagesUtility $responsiv
$this->responsiveImagesUtility = $responsiveImagesUtility;
}

/**
* @param ConfigurationManager $configurationManager
*/
public function injectConfigurationManager(ConfigurationManager $configurationManager)
{
$this->configurationManager = $configurationManager;
}

/**
* Initialize arguments.
*/
Expand Down Expand Up @@ -258,7 +272,8 @@ protected function renderImageTag(FileInterface $image, $width, $height, $fileEx
$imageService = $this->getImageService();
$processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);

$webpIsLoaded = ExtensionManagementUtility::isLoaded('webp');
$settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
$webpIsLoaded = (bool)$settings['page.']['10.']['settings.']['webp'];
if ( $webpIsLoaded ) {
$webpIdentifier = $processedImage->getIdentifier().'.webp';
$processedImage->setIdentifier($webpIdentifier);
Expand Down

0 comments on commit 3b3c1e4

Please sign in to comment.