Skip to content

Commit

Permalink
[BUGFIX] Read max width and height from page TSConfig
Browse files Browse the repository at this point in the history
* use correct route URL, that includes the current records PID
* apply the maximum width and height from page TSConfig, when processing the image
* return the correct width and height properties to apply in the image dialog
  • Loading branch information
thommyhh committed Sep 5, 2024
1 parent 2096580 commit 985e159
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 39 deletions.
34 changes: 25 additions & 9 deletions Classes/Controller/SelectImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Exception;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Configuration\Richtext;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Resource\File;
Expand Down Expand Up @@ -98,14 +99,15 @@ public function infoAction(ServerRequestInterface $request): ResponseInterface
}

$file = $this->getImage((int) $id);
$processedFile = $this->processImage($file, $params);
$maxDimensions = $this->getMaxDimensions($params);
$processedFile = $this->processImage($file, $params, $maxDimensions);

return new JsonResponse([
'uid' => $file->getUid(),
'alt' => $file->getProperty('alternative') ?? '',
'title' => $file->getProperty('title') ?? '',
'width' => $file->getProperty('width'),
'height' => $file->getProperty('height'),
'width' => min($file->getProperty('width'), $maxDimensions['width']),
'height' => min($file->getProperty('height'), $maxDimensions['height']),
'url' => $file->getPublicUrl(),
'processed' => [
'width' => $processedFile->getProperty('width'),
Expand Down Expand Up @@ -163,21 +165,21 @@ protected function getImage(int $id): File
/**
* Get the processed image.
*
* @param File $file The original image file
* @param string[] $params The parameters used to process the image
* @param File $file The original image file
* @param string[] $params The parameters used to process the image
* @param array $maxDimensions The maximum width and height
*
* @return ProcessedFile
*/
protected function processImage(File $file, array $params): ProcessedFile
protected function processImage(File $file, array $params, array $maxDimensions): ProcessedFile

Check failure on line 174 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.1 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::processImage() has parameter $maxDimensions with no value type specified in iterable type array.

Check failure on line 174 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.2 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::processImage() has parameter $maxDimensions with no value type specified in iterable type array.

Check failure on line 174 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.3 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::processImage() has parameter $maxDimensions with no value type specified in iterable type array.

Check failure on line 174 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.1 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::processImage() has parameter $maxDimensions with no value type specified in iterable type array.

Check failure on line 174 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.2 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::processImage() has parameter $maxDimensions with no value type specified in iterable type array.

Check failure on line 174 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.3 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::processImage() has parameter $maxDimensions with no value type specified in iterable type array.
{
// TODO: Get this from page ts config
$this->magicImageService->setMagicImageMaximumDimensions([
'buttons.' => [
'image.' => [
'options.' => [
'magic.' => [
'maxWidth' => 1920,
'maxHeight' => 9999,
'maxWidth' => $maxDimensions['width'],
'maxHeight' => $maxDimensions['height'],
]
]
]
Expand All @@ -193,4 +195,18 @@ protected function processImage(File $file, array $params): ProcessedFile
]
);
}

protected function getMaxDimensions(array $params): array

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.1 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() has parameter $params with no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.1 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() return type has no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.2 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() has parameter $params with no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.2 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() return type has no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.3 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() has parameter $params with no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.3 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() return type has no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.1 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() has parameter $params with no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.1 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() return type has no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.2 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() has parameter $params with no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.2 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() return type has no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.3 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() has parameter $params with no value type specified in iterable type array.

Check failure on line 199 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.3 on ubuntu-24.04

Method Netresearch\RteCKEditorImage\Controller\SelectImageController::getMaxDimensions() return type has no value type specified in iterable type array.
{
$tsConfig = BackendUtility::getPagesTSconfig($params['pid'] ?? 0);
$richtextConfigurationName = $params['richtextConfigurationName'] ?? 'default';
if (empty($richtextConfigurationName)) {

Check failure on line 203 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.1 on ubuntu-24.04

Construct empty() is not allowed. Use more strict comparison.

Check failure on line 203 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.2 on ubuntu-24.04

Construct empty() is not allowed. Use more strict comparison.

Check failure on line 203 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.3 on ubuntu-24.04

Construct empty() is not allowed. Use more strict comparison.

Check failure on line 203 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.1 on ubuntu-24.04

Construct empty() is not allowed. Use more strict comparison.

Check failure on line 203 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.2 on ubuntu-24.04

Construct empty() is not allowed. Use more strict comparison.

Check failure on line 203 in Classes/Controller/SelectImageController.php

View workflow job for this annotation

GitHub Actions / Testing PHP 8.3 on ubuntu-24.04

Construct empty() is not allowed. Use more strict comparison.
$richtextConfigurationName = 'default';
}
$rteConfig = $tsConfig['RTE.'][$richtextConfigurationName . '.'];
$maxHeight = $rteConfig['buttons.']['image.']['options.']['magic.']['maxHeight'] ?? 9999;
$maxWidth = $rteConfig['buttons.']['image.']['options.']['magic.']['maxWidth'] ?? 1920;

return ['width' => $maxWidth, 'height' => $maxHeight];
}
}
21 changes: 0 additions & 21 deletions Classes/EventListener/RteConfigurationListener.php

This file was deleted.

8 changes: 1 addition & 7 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,5 @@ services:
Netresearch\RteCKEditorImage\Database\RteImagesDbHook:
public: true

Netresearch\RteCKEditorImage\EventListener\RteConfigurationListener:
tags:
- name: event.listener
identifier: 'rte_configuration_listener'
event: TYPO3\CMS\RteCKEditor\Form\Element\Event\AfterPrepareConfigurationForEditorEvent

Netresearch\RteCKEditorImage\Controller\SelectImageController:
tags: ['backend.controller']
tags: ['backend.controller']
4 changes: 2 additions & 2 deletions Resources/Public/JavaScript/Plugins/typo3image.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ function askImageAttributes(editor, img, attributes, table) {
* @return {$.Deferred}
*/
function getImageInfo(editor, table, uid, params) {
let url = editor.config.get('style').typo3image.routeUrl + '&action=info&fileId=' + encodeURIComponent(uid) + '&table=' + encodeURIComponent(table) + '&contentsLanguage=en&editorId=123';
let url = editor.config.get('typo3image').routeUrl + '&action=info&fileId=' + encodeURIComponent(uid) + '&table=' + encodeURIComponent(table) + '&contentsLanguage=en&editorId=123';

if (typeof params.width !== 'undefined' && params.width.length) {
url += '&P[width]=' + params.width;
Expand All @@ -357,7 +357,7 @@ function selectImage(editor) {
];

// TODO: Use ajaxUrl
const contentUrl = editor.config.get('style').typo3image.routeUrl + '&contentsLanguage=en&editorId=123&bparams=' + bparams.join('|');
const contentUrl = editor.config.get('typo3image').routeUrl + '&contentsLanguage=en&editorId=123&bparams=' + bparams.join('|');

const modal = Modal.advanced({
type: Modal.types.iframe,
Expand Down

0 comments on commit 985e159

Please sign in to comment.