-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Provide VH to render icons for resources
Provide a ViewHelper to render the markup to show an icon for files and folders. Resolves: #83942 Releases: master Change-Id: I44a99f3e06dc35b98b3e29f509432a8575c29807 Reviewed-on: https://review.typo3.org/55759 Reviewed-by: Frank Naegler <frank.naegler@typo3.org> Tested-by: Frank Naegler <frank.naegler@typo3.org> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: TYPO3com <no-reply@typo3.com>
- Loading branch information
1 parent
c5d57fe
commit 537d74c
Showing
6 changed files
with
146 additions
and
16 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
typo3/sysext/core/Classes/ViewHelpers/IconForResourceViewHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
namespace TYPO3\CMS\Core\ViewHelpers; | ||
|
||
/* | ||
* 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 TYPO3\CMS\Core\Imaging\Icon; | ||
use TYPO3\CMS\Core\Imaging\IconFactory; | ||
use TYPO3\CMS\Core\Resource\ResourceInterface; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; | ||
|
||
/** | ||
* Displays icon for a FAL resource (file or folder means a TYPO3\CMS\Core\Resource\ResourceInterface) | ||
*/ | ||
class IconForResourceViewHelper extends AbstractViewHelper | ||
{ | ||
use CompileWithRenderStatic; | ||
|
||
/** | ||
* View helper returns HTML, thus we need to disable output escaping | ||
* | ||
* @var bool | ||
*/ | ||
protected $escapeOutput = false; | ||
|
||
/** | ||
* Initializes the arguments | ||
*/ | ||
public function initializeArguments() | ||
{ | ||
$this->registerArgument('resource', ResourceInterface::class, 'Resource', true); | ||
$this->registerArgument('size', 'string', 'The icon size', false, Icon::SIZE_SMALL); | ||
$this->registerArgument('overlay', 'string', 'Overlay identifier', false, null); | ||
$this->registerArgument('options', 'array', 'An associative array with additional options', false, []); | ||
$this->registerArgument('alternativeMarkupIdentifier', 'string', 'Alternative markup identifier', false, null); | ||
} | ||
|
||
/** | ||
* @param array $arguments | ||
* @param \Closure $renderChildrenClosure | ||
* @param RenderingContextInterface $renderingContext | ||
* @return string | ||
*/ | ||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string | ||
{ | ||
$resource = $arguments['resource']; | ||
$size = $arguments['size']; | ||
$overlay = $arguments['overlay']; | ||
$iconFactory = GeneralUtility::makeInstance(IconFactory::class); | ||
return $iconFactory->getIconForResource($resource, $size, $overlay, $arguments['options'])->render($arguments['alternativeMarkupIdentifier']); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ocumentation/Changelog/master/Deprecation-83942-DeprecatedFileFacadegetIcon.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.. include:: ../../Includes.txt | ||
|
||
==================================================== | ||
Deprecation: #83942 - Deprecated FileFacade::getIcon | ||
==================================================== | ||
|
||
See :issue:`83942` | ||
|
||
Description | ||
=========== | ||
|
||
The method :php:`\TYPO3\CMS\Filelist\FileFacade::getIcon` has been marked as deprecated. | ||
|
||
|
||
Impact | ||
====== | ||
|
||
Calling the method :php:`\TYPO3\CMS\Filelist\FileFacade::getIcon` will trigger a deprecation warning. | ||
|
||
|
||
Affected Installations | ||
====================== | ||
|
||
Instances with extensions using the method :php:`\TYPO3\CMS\Filelist\FileFacade::getIcon` | ||
|
||
|
||
Migration | ||
========= | ||
|
||
Either use the ViewHelper :html:`<core:iconForResource resource="{file}" />` or | ||
:php:`GeneralUtility::makeInstance(IconFactory::class)->getIconForResource($resource)` to render a resource-based icon. | ||
|
||
.. index:: FAL, FullyScanned |
20 changes: 20 additions & 0 deletions
20
...on/Changelog/master/Feature-83942-ProvideViewHelperToRenderIconForResources.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.. include:: ../../Includes.txt | ||
|
||
================================================================= | ||
Feature: #83942 - Provide ViewHelper to render icon for resources | ||
================================================================= | ||
|
||
See :issue:`83942` | ||
|
||
Description | ||
=========== | ||
|
||
A new ViewHelper to render the icon markup based on a FAL resource has been introduced. | ||
|
||
Example: | ||
|
||
.. code-block:: html | ||
|
||
<core:iconForResource resource="{file}" /> | ||
|
||
.. index:: Backend, Fluid, ext:core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters