Skip to content

Commit

Permalink
[TASK] TYPO3 CMS 8 Compactibility Viewhelpers added
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 9 deletions.
118 changes: 118 additions & 0 deletions Classes/ViewHelpers/Be/Buttons/IconViewHelper.php
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>';
}
}
110 changes: 110 additions & 0 deletions Classes/ViewHelpers/Be/Buttons/ShortcutViewHelper.php
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 '';
}
}
11 changes: 6 additions & 5 deletions Resources/Private/Layouts/Default.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{namespace TB=Tutorboy\Blogmaster\ViewHelpers}
<f:be.container
includeCssFiles="{0: '{f:uri.resource(path:\'Css/Backend.css\')}'}"
enableClickMenu="false"
Expand All @@ -14,11 +15,11 @@
<f:be.pagePath /> > <f:translate key="project.shortDescription"/>
</div>
<div class="module-docheader-bar-column-right">
<f:be.buttons.icon uri="javascript:window.location.reload(true);" icon="actions-refresh" title="<f:translate key='label.refresh'/>" />
<f:be.buttons.shortcut />
<a href="https://github.com/midhundevasia/typo3-blogmaster/wiki" target="_blank" title="<f:translate key='label.documentation'/>"><f:be.buttons.icon icon="extension-blogmaster-help"/></a>
<a href="https://github.com/midhundevasia/typo3-blogmaster/issues" target="_blank" title="<f:translate key='label.bugs'/>"><f:be.buttons.icon icon="extension-blogmaster-bugs"/></a>
<a href="http://midhundevasia.com/donate/" target="_blank" title="<f:translate key='label.support'/>"><f:be.buttons.icon icon="extension-blogmaster-donate"/></a>
<TB:be.buttons.icon uri="javascript:window.location.reload(true);" icon="actions-refresh" title="<f:translate key='label.refresh'/>" />
<TB:be.buttons.shortcut />
<a href="https://github.com/midhundevasia/typo3-blogmaster/wiki" target="_blank" title="<f:translate key='label.documentation'/>"><TB:be.buttons.icon icon="extension-blogmaster-help"/></a>
<a href="https://github.com/midhundevasia/typo3-blogmaster/issues" target="_blank" title="<f:translate key='label.bugs'/>"><TB:be.buttons.icon icon="extension-blogmaster-bugs"/></a>
<a href="http://midhundevasia.com/donate/" target="_blank" title="<f:translate key='label.support'/>"><TB:be.buttons.icon icon="extension-blogmaster-donate"/></a>
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions Resources/Private/Partials/Post/Sidebar/Tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<f:for each="{tagList}" as="tag">
<span class="btn btn-default tag-item-{tag.uid}">
<a href="javascript:removeTag({tag.uid})">
<f:be.buttons.icon icon="ext-blogmaster-close"/>
<TB:be.buttons.icon icon="ext-blogmaster-close"/>
</a>
<f:form.checkbox property="tags" value="{tag.uid}" class="hide"/>{tag.title}</span>
</f:for>
Expand All @@ -30,8 +30,8 @@
</div>
</div>
<script type="text/javascript">
var closeIcon = '<TB:format.removeNl><f:be.buttons.icon icon="ext-blogmaster-close"/></TB:format.removeNl>';
var plusIcon = '<TB:format.removeNl><f:be.buttons.icon icon="ext-blogmaster-plus"/></TB:format.removeNl>';
var closeIcon = '<TB:format.removeNl><TB:be.buttons.icon icon="ext-blogmaster-close"/></TB:format.removeNl>';
var plusIcon = '<TB:format.removeNl><TB:be.buttons.icon icon="ext-blogmaster-plus"/></TB:format.removeNl>';
var postId = '{postObject.uid}';
function removeTag(currentTag) {
TYPO3.jQuery('.tag-item-' + currentTag).find('input').attr('checked', false).parent().hide();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{namespace TB=Tutorboy\Blogmaster\ViewHelpers}
<div class="panel panel-space panel-default clear">
<div class="panel-heading">
{title}
<span>
<a href="javascript:void(0);" title="Collapse" class="pull-right t3js-toggle-recordlist" data-toggle="collapse" aria-expanded="true">
<f:be.buttons.icon icon="ext-blogmaster-collapse"/>
<TB:be.buttons.icon icon="ext-blogmaster-collapse"/>
</a>
</span>
</div>
Expand Down

0 comments on commit dea282a

Please sign in to comment.