-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] TYPO3 CMS 8 Compactibility Viewhelpers added
Replaced <f:be.buttons.icon to <blog:be.buttons.icons/> Replaced <f:be.buttons.shortcut to <blog:be.buttons.shortcut/>
- Loading branch information
Midhun Devasia
committed
Nov 25, 2016
1 parent
5b2f061
commit dea282a
Showing
5 changed files
with
239 additions
and
9 deletions.
There are no files selected for viewing
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,118 @@ | ||
<?php | ||
namespace Tutorboy\Blogmaster\ViewHelpers\Be\Buttons; | ||
|
||
/* | ||
* This file is part of the Blogmaster project. | ||
* Copyright (C) 2016 Midhun Devasia <[email protected]> | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 3 | ||
* 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. | ||
* | ||
* Blogmaster - A blog system for TYPO3! | ||
*/ | ||
|
||
use TYPO3\CMS\Core\Imaging\Icon; | ||
use TYPO3\CMS\Core\Imaging\IconFactory; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; | ||
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; | ||
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper; | ||
|
||
/** | ||
* View helper which returns a button icon | ||
* | ||
* @package Blogmaster | ||
* @subpackage ViewHelper | ||
* @copyright (c) 2016 Midhun Devasia, Tutorboy.org | ||
* @author Midhun Devasia <[email protected]> | ||
* | ||
* = Examples = | ||
* | ||
* <code title="Default"> | ||
* <f:be.buttons.icon uri="{f:uri.action()}" /> | ||
* </code> | ||
* <output> | ||
* An icon button as known from the TYPO3 backend, skinned and linked with the default action of the current controller. | ||
* Note: By default the "close" icon is used as image | ||
* </output> | ||
* | ||
* <code title="Default"> | ||
* <f:be.buttons.icon uri="{f:uri.action(action:'new')}" icon="actions-document-new" title="Create new Foo" /> | ||
* </code> | ||
* | ||
* <code title="Default"> | ||
* <f:be.buttons.icon icon="actions-document-new" title="Create new Foo" /> | ||
* </code> | ||
* <output> | ||
* Here the "actions-document-new" icon is returned, but without link. | ||
* </output> | ||
*/ | ||
class IconViewHelper extends AbstractBackendViewHelper implements CompilableInterface { | ||
|
||
/** | ||
* View helper returns HTML, thus we need to disable output escaping | ||
* | ||
* @var bool | ||
*/ | ||
protected $escapeOutput = FALSE; | ||
|
||
/** | ||
* Renders a linked icon as known from the TYPO3 backend. | ||
* | ||
* If the URI is left empty, the icon is rendered without link. | ||
* | ||
* @param string $uri The target URI for the link. If you want to execute JavaScript here, prefix the URI with | ||
* "javascript:". Leave empty to render just an icon. | ||
* @param string $icon Icon to be used. | ||
* @param string $title Title attribute of the icon construct | ||
* @param array $additionalAttributes Additional tag attributes. They will be added directly to the resulting HTML tag. | ||
* | ||
* @return string The rendered icon with or without link | ||
* @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use \TYPO3\CMS\Core\ViewHelpers\IconViewHelper instead | ||
*/ | ||
public function render($uri = '', $icon = 'actions-document-close', $title = '', array $additionalAttributes = []) { | ||
return static::renderStatic( | ||
[ | ||
'uri' => $uri, | ||
'icon' => $icon, | ||
'title' => $title, | ||
'additionalAttributes' => $additionalAttributes | ||
], | ||
$this->buildRenderChildrenClosure(), | ||
$this->renderingContext | ||
); | ||
} | ||
|
||
/** | ||
* Render | ||
* @param array $arguments arguments | ||
* @param \Closure $renderChildrenClosure renderChildrenClosure | ||
* @param RenderingContextInterface $renderingContext renderingContext | ||
* @return string | ||
* @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use \TYPO3\CMS\Core\ViewHelpers\IconViewHelper instead | ||
*/ | ||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { | ||
GeneralUtility::logDeprecatedFunction(); | ||
$uri = $arguments['uri']; | ||
$icon = $arguments['icon']; | ||
$title = $arguments['title']; | ||
$additionalAttributes = $arguments['additionalAttributes']; | ||
$additionalTagAttributes = ''; | ||
$iconFactory = GeneralUtility::makeInstance(IconFactory::class); | ||
$icon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render() . '</span>'; | ||
if (empty($uri)) { | ||
return $icon; | ||
} | ||
|
||
if ($additionalAttributes) { | ||
foreach ($additionalAttributes as $argumentKey => $argumentValue) { | ||
$additionalTagAttributes .= ' ' . $argumentKey . '="' . htmlspecialchars($argumentValue) . '"'; | ||
} | ||
} | ||
return '<a href="' . $uri . '"' . $additionalTagAttributes . '>' . $icon . '</a>'; | ||
} | ||
} |
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,110 @@ | ||
<?php | ||
namespace Tutorboy\Blogmaster\ViewHelpers\Be\Buttons; | ||
|
||
/* | ||
* This file is part of the Blogmaster project. | ||
* Copyright (C) 2016 Midhun Devasia <[email protected]> | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 3 | ||
* 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. | ||
* | ||
* Blogmaster - A blog system for TYPO3! | ||
*/ | ||
|
||
use TYPO3\CMS\Backend\Template\DocumentTemplate; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; | ||
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; | ||
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper; | ||
|
||
/** | ||
* View helper which returns shortcut button with icon | ||
* Note: This view helper is experimental! | ||
* | ||
* @package Blogmaster | ||
* @subpackage ViewHelper | ||
* @copyright (c) 2016 Midhun Devasia, Tutorboy.org | ||
* @author Midhun Devasia <[email protected]> * = Examples = | ||
* | ||
* <code title="Default"> | ||
* <f:be.buttons.shortcut /> | ||
* </code> | ||
* <output> | ||
* Shortcut button as known from the TYPO3 backend. | ||
* By default the current page id, module name and all module arguments will be stored | ||
* </output> | ||
* | ||
* <code title="Explicitly set parameters to be stored in the shortcut"> | ||
* <f:be.buttons.shortcut getVars="{0: 'M', 1: 'myOwnPrefix'}" setVars="{0: 'function'}" /> | ||
* </code> | ||
* <output> | ||
* Shortcut button as known from the TYPO3 backend. | ||
* This time only the specified GET parameters and SET[]-settings will be stored. | ||
* Note: | ||
* Normally you won't need to set getVars & setVars parameters in Extbase modules | ||
* </output> | ||
*/ | ||
class ShortcutViewHelper extends AbstractBackendViewHelper implements CompilableInterface { | ||
|
||
/** | ||
* View helper returns HTML, thus we need to disable output escaping | ||
* | ||
* @var bool | ||
*/ | ||
protected $escapeOutput = FALSE; | ||
|
||
/** | ||
* Renders a shortcut button as known from the TYPO3 backend | ||
* | ||
* @param array $getVars list of GET variables to store. By default the current id, module and all module arguments | ||
* will be stored | ||
* @param array $setVars list of SET[] variables to store. See | ||
* \TYPO3\CMS\Backend\Template\DocumentTemplate::makeShortcutIcon(). Normally won't be used by Extbase modules | ||
* | ||
* @return string the rendered shortcut button | ||
* @see \TYPO3\CMS\Backend\Template\DocumentTemplate::makeShortcutIcon() | ||
*/ | ||
public function render(array $getVars = [], array $setVars = []) { | ||
return static::renderStatic( | ||
[ | ||
'getVars' => $getVars, | ||
'setVars' => $setVars | ||
], | ||
$this->buildRenderChildrenClosure(), | ||
$this->renderingContext | ||
); | ||
} | ||
|
||
/** | ||
* Render | ||
* @param array $arguments Arguments | ||
* @param \Closure $renderChildrenClosure renderChildrenClosure | ||
* @param RenderingContextInterface $renderingContext renderingContext | ||
* @return string | ||
*/ | ||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { | ||
$getVars = $arguments['getVars']; | ||
$setVars = $arguments['setVars']; | ||
|
||
$mayMakeShortcut = $GLOBALS['BE_USER']->mayMakeShortcut(); | ||
|
||
if ($mayMakeShortcut) { | ||
$doc = GeneralUtility::makeInstance(DocumentTemplate::class); | ||
$currentRequest = $renderingContext->getControllerContext()->getRequest(); | ||
$extensionName = $currentRequest->getControllerExtensionName(); | ||
$moduleName = $currentRequest->getPluginName(); | ||
if (count($getVars) === 0) { | ||
$modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName); | ||
$getVars = ['id', 'M', $modulePrefix]; | ||
} | ||
$getList = implode(',', $getVars); | ||
$setList = implode(',', $setVars); | ||
return $doc->makeShortcutIcon($getList, $setList, $moduleName); | ||
} | ||
return ''; | ||
} | ||
} |
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