Skip to content

Commit

Permalink
[TASK] Extract request processing from IconFactory
Browse files Browse the repository at this point in the history
Change-Id: If23a7a356e62a17dad4f22a746c365ef094999da
Resolves: #84408
Releases: master
Reviewed-on: https://review.typo3.org/56321
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
mbrodala authored and lolli42 committed Mar 17, 2018
1 parent 2912053 commit 760f491
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
2 changes: 1 addition & 1 deletion typo3/sysext/backend/Configuration/Backend/AjaxRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
// Get icon from IconFactory
'icons' => [
'path' => '/icons',
'target' => \TYPO3\CMS\Core\Imaging\IconFactory::class . '::processAjaxRequest'
'target' => \TYPO3\CMS\Core\Controller\IconController::class . '::getIcon'
],

// Encode typolink parts on demand
Expand Down
65 changes: 65 additions & 0 deletions typo3/sysext/core/Classes/Controller/IconController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Core\Controller;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Type\Icon\IconState;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Controller for icon handling
*/
class IconController
{
/**
* @var IconFactory
*/
protected $iconFactory;

/**
* Set up dependencies
*/
public function __construct()
{
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
* @internal
*/
public function getIcon(ServerRequestInterface $request): ResponseInterface
{
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
$requestedIcon = json_decode($parsedBody['icon'] ?? $queryParams['icon'], true);

list($identifier, $size, $overlayIdentifier, $iconState, $alternativeMarkupIdentifier) = $requestedIcon;

if (empty($overlayIdentifier)) {
$overlayIdentifier = null;
}

$iconState = IconState::cast($iconState);
$icon = $this->iconFactory->getIcon($identifier, $size, $overlayIdentifier, $iconState);

return new HtmlResponse($icon->render($alternativeMarkupIdentifier));
}
}
25 changes: 0 additions & 25 deletions typo3/sysext/core/Classes/Imaging/IconFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
* The TYPO3 project - inspiring people to share!
*/

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FolderInterface;
use TYPO3\CMS\Core\Resource\InaccessibleFolder;
Expand Down Expand Up @@ -70,28 +67,6 @@ public function __construct(IconRegistry $iconRegistry = null)
$this->overlayPriorities = $GLOBALS['TYPO3_CONF_VARS']['SYS']['IconFactory']['overlayPriorities'];
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
* @internal
*/
public function processAjaxRequest(ServerRequestInterface $request): ResponseInterface
{
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
$requestedIcon = json_decode(
$parsedBody['icon'] ?? $queryParams['icon'],
true
);

list($identifier, $size, $overlayIdentifier, $iconState, $alternativeMarkupIdentifier) = $requestedIcon;
if (empty($overlayIdentifier)) {
$overlayIdentifier = null;
}
$iconState = IconState::cast($iconState);
return new HtmlResponse($this->getIcon($identifier, $size, $overlayIdentifier, $iconState)->render($alternativeMarkupIdentifier));
}

/**
* @param string $identifier
* @param string $size "large", "small" or "default", see the constants of the Icon class
Expand Down

0 comments on commit 760f491

Please sign in to comment.