From 111c29f9d0f55ec86c713d75085bdd90db5cbf99 Mon Sep 17 00:00:00 2001 From: Georg Ringer <georg.ringer@gmail.com> Date: Thu, 15 Feb 2018 13:42:40 +0100 Subject: [PATCH] [TASK] Move HTML generation in RemoveUserViewHelper to the view 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> --- .../Controller/BackendUserController.php | 1 + .../ViewHelpers/RemoveUserViewHelper.php | 37 ++----------------- .../Partials/BackendUser/IndexListRow.html | 16 +++++++- .../BackendUser/PaginatedListWidget.html | 2 +- .../BackendUser/PaginatedListWidgetBody.html | 4 +- .../PaginatedListWidgetBody.html | 4 +- .../Private/Templates/BackendUser/Index.html | 1 - 7 files changed, 25 insertions(+), 40 deletions(-) diff --git a/typo3/sysext/beuser/Classes/Controller/BackendUserController.php b/typo3/sysext/beuser/Classes/Controller/BackendUserController.php index 1e3a237fb808..b3e342536fa8 100644 --- a/typo3/sysext/beuser/Classes/Controller/BackendUserController.php +++ b/typo3/sysext/beuser/Classes/Controller/BackendUserController.php @@ -166,6 +166,7 @@ class BackendUserController extends BackendUserActionController $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) : ''); } diff --git a/typo3/sysext/beuser/Classes/ViewHelpers/RemoveUserViewHelper.php b/typo3/sysext/beuser/Classes/ViewHelpers/RemoveUserViewHelper.php index 13370652b7b7..254d030a595e 100644 --- a/typo3/sysext/beuser/Classes/ViewHelpers/RemoveUserViewHelper.php +++ b/typo3/sysext/beuser/Classes/ViewHelpers/RemoveUserViewHelper.php @@ -16,17 +16,13 @@ namespace TYPO3\CMS\Beuser\ViewHelpers; 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 */ @@ -34,13 +30,6 @@ 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 */ @@ -50,7 +39,7 @@ class RemoveUserViewHelper extends AbstractViewHelper } /** - * Render link with sprite icon to remove user + * Renders the URL to remove a user. * * @param array $arguments * @param \Closure $renderChildrenClosure @@ -60,29 +49,11 @@ class RemoveUserViewHelper extends AbstractViewHelper */ 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); } } diff --git a/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/IndexListRow.html b/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/IndexListRow.html index a33f43be5dc1..fec20abc7655 100644 --- a/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/IndexListRow.html +++ b/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/IndexListRow.html @@ -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> diff --git a/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/PaginatedListWidget.html b/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/PaginatedListWidget.html index 598ecaa782e8..a5f11ea5b938 100644 --- a/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/PaginatedListWidget.html +++ b/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/PaginatedListWidget.html @@ -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> \ No newline at end of file +</f:be.widget.paginate> diff --git a/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/PaginatedListWidgetBody.html b/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/PaginatedListWidgetBody.html index e16b5d97b30a..d1d812f6bd61 100644 --- a/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/PaginatedListWidgetBody.html +++ b/typo3/sysext/beuser/Resources/Private/Partials/BackendUser/PaginatedListWidgetBody.html @@ -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 @@ -24,4 +24,4 @@ </tr> </tfoot> </table> -</div> \ No newline at end of file +</div> diff --git a/typo3/sysext/beuser/Resources/Private/Partials/BackendUserGroup/PaginatedListWidgetBody.html b/typo3/sysext/beuser/Resources/Private/Partials/BackendUserGroup/PaginatedListWidgetBody.html index 2982a438ee64..476d660da57c 100644 --- a/typo3/sysext/beuser/Resources/Private/Partials/BackendUserGroup/PaginatedListWidgetBody.html +++ b/typo3/sysext/beuser/Resources/Private/Partials/BackendUserGroup/PaginatedListWidgetBody.html @@ -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 @@ -22,4 +22,4 @@ </tr> </tbody> </table> -</div> \ No newline at end of file +</div> diff --git a/typo3/sysext/beuser/Resources/Private/Templates/BackendUser/Index.html b/typo3/sysext/beuser/Resources/Private/Templates/BackendUser/Index.html index 279f2e881ac2..6adad084c113 100644 --- a/typo3/sysext/beuser/Resources/Private/Templates/BackendUser/Index.html +++ b/typo3/sysext/beuser/Resources/Private/Templates/BackendUser/Index.html @@ -8,7 +8,6 @@ </f:section> <f:section name="content"> - <f:comment> Listing of users on compare list </f:comment> -- GitLab