Skip to content

Commit

Permalink
[TASK] Move HTML generation in RemoveUserViewHelper to the view
Browse files Browse the repository at this point in the history
Instead of creating the HTML in the ViewHelper it should be done in
the template.

Resolves: #83918
Releases: master
Change-Id: I8e9aaf51f23cd8808cc2910d6e8668f27671cf66
Reviewed-on: https://review.typo3.org/55733
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
georgringer authored and lolli42 committed Feb 17, 2018
1 parent 2348992 commit 111c29f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public function indexAction(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand = null
$this->view->assign('compareUserUidList', array_map(function ($item) {
return true;
}, array_flip((array)$compareUserList)));
$this->view->assign('currentUserUid', $this->getBackendUserAuthentication()->user['uid']);
$this->view->assign('compareUserList', !empty($compareUserList) ? $this->backendUserRepository->findByUidList($compareUserList) : '');
}

Expand Down
37 changes: 4 additions & 33 deletions typo3/sysext/beuser/Classes/ViewHelpers/RemoveUserViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,20 @@

use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Displays 'Delete user' link with sprite icon to remove user
* Renders 'Delete user' link
*
* @internal
*/
class RemoveUserViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* @var bool
*/
protected $escapeOutput = false;

/**
* Initializes the arguments
*/
Expand All @@ -50,7 +39,7 @@ public function initializeArguments()
}

/**
* Render link with sprite icon to remove user
* Renders the URL to remove a user.
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
Expand All @@ -60,29 +49,11 @@ public function initializeArguments()
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var \TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser */
$backendUser = $arguments['backendUser'];
/** @var BackendUserAuthentication $beUser */
$beUser = $GLOBALS['BE_USER'];
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
if ($backendUser->getUid() === (int)$beUser->user['uid']) {
return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
}

$urlParameters = [
'cmd[be_users][' . $backendUser->getUid() . '][delete]' => 1,
'cmd[be_users][' . $arguments['backendUser']->getUid() . '][delete]' => 1,
'redirect' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$url = (string)$uriBuilder->buildUriFromRoute('tce_db', $urlParameters);

return '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars($url) . '"'
. ' title="' . htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:delete')) . '"'
. ' data-severity="warning"'
. ' data-title="' . htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_alt_doc.xlf:label.confirm.delete_record.title')) . '"'
. ' data-content="' . htmlspecialchars(LocalizationUtility::translate('confirm', 'beuser', [$backendUser->getUserName()])) . '" '
. ' data-button-close-text="' . htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:cancel')) . '"'
. '>' . $iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
return (string)$uriBuilder->buildUriFromRoute('tce_db', $urlParameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@
</f:if>
</f:else>
</f:if>
<bu:removeUser backendUser="{backendUser}" />
<f:if condition="{currentUserUid} == {backendUser.uid}">
<f:then>
<span class="btn btn-default disabled"><core:icon identifier="empty-empty" /></span>
</f:then>
<f:else>
<a class="btn btn-default t3js-modal-trigger" href="{bu:removeUser(backendUser:backendUser)}"
title="{f:translate(key:'LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:delete')}"
data-severity="warning"
data-title="{f:translate(key:'LLL:EXT:lang/Resources/Private/Language/locallang_alt_doc.xlf:label.confirm.delete_record.title')}"
data-content="{f:translate(key:'confirm',arguments:'{0:backendUser.userName}')}"
data-button-close-text="{f:translate(key:'LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:cancel')}">
<core:icon identifier="actions-edit-delete" />
</a>
</f:else>
</f:if>
</div>
<div class="btn-group" role="group">
<a class="btn btn-default" href="#" onclick="top.TYPO3.InfoWindow.showItem('be_users', '{backendUser.uid}'); return false;"><core:icon identifier="actions-document-info" /></a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<f:be.widget.paginate objects="{backendUsers}" as="paginatedBackendUsers" configuration="{itemsPerPage: 50, insertBelow: 1}">
<f:render partial="BackendUser/PaginatedListWidgetBody" arguments="{_all}" />
</f:be.widget.paginate>
</f:be.widget.paginate>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</thead>
<tbody>
<f:for each="{paginatedBackendUsers}" as="backendUser">
<f:render partial="BackendUser/IndexListRow" arguments="{demand: demand, backendUser: backendUser, onlineBackendUsers: onlineBackendUsers, dateFormat: dateFormat, timeFormat: timeFormat, returnUrl: returnUrl, compareUserUidList: compareUserUidList}" />
<f:render partial="BackendUser/IndexListRow" arguments="{demand: demand, backendUser: backendUser, onlineBackendUsers: onlineBackendUsers, dateFormat: dateFormat, timeFormat: timeFormat, returnUrl: returnUrl, compareUserUidList: compareUserUidList, currentUserUid: currentUserUid}" />
</f:for>
<f:comment>
Footer row: no officially defined style yet
Expand All @@ -24,4 +24,4 @@
</tr>
</tfoot>
</table>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</thead>
<tbody>
<f:for each="{paginatedBackendUserGroups}" as="backendUserGroup">
<f:render partial="BackendUserGroup/IndexListRow" arguments="{demand: demand, backendUserGroup: backendUserGroup, dateFormat: dateFormat, timeFormat: timeFormat, returnUrl: returnUrl}" />
<f:render partial="BackendUserGroup/IndexListRow" arguments="{demand: demand, backendUserGroup: backendUserGroup, dateFormat: dateFormat, timeFormat: timeFormat, returnUrl: returnUrl, currentUserUid: currentUserUid}" />
</f:for>
<f:comment>
Footer row: no officially defined style yet
Expand All @@ -22,4 +22,4 @@
</tr>
</tbody>
</table>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ <h1><f:translate key="backendUserListing" /></h1>
</f:section>

<f:section name="content">

<f:comment>
Listing of users on compare list
</f:comment>
Expand Down

0 comments on commit 111c29f

Please sign in to comment.