0476807f4f8ba48a9d7e2cb2a988f3d5a5c9b229
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / ViewHelpers / RemoveUserViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Beuser\ViewHelpers;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\IconUtility;
18 use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
24 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
25 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
26
27 /**
28 * Displays 'Delete user' link with sprite icon to remove user
29 *
30 * @internal
31 */
32 class RemoveUserViewHelper extends AbstractViewHelper implements CompilableInterface {
33
34 /**
35 * Render link with sprite icon to remove user
36 *
37 * @param \TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser Target backendUser to switch active session to
38 * @return string
39 */
40 public function render(BackendUser $backendUser) {
41 return static::renderStatic(
42 array(
43 'backendUser' => $backendUser
44 ),
45 $this->buildRenderChildrenClosure(),
46 $this->renderingContext
47 );
48 }
49
50 /**
51 * @param array $arguments
52 * @param callable $renderChildrenClosure
53 * @param RenderingContextInterface $renderingContext
54 *
55 * @return string
56 */
57 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
58 /** @var \TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser */
59 $backendUser = $arguments['backendUser'];
60 /** @var BackendUserAuthentication $beUser */
61 $beUser = $GLOBALS['BE_USER'];
62 if ($backendUser->getUid() === (int)$beUser->user['uid']) {
63 return '<span class="btn btn-default disabled">' . IconUtility::getSpriteIcon('empty-empty') . '</span>';
64 }
65
66 $urlParameters = [
67 'cmd[be_users][' . $backendUser->getUid() . '][delete]' => 1,
68 'vC' => $beUser->veriCode(),
69 'prErr' => 1,
70 'uPT' => 1,
71 'redirect' => GeneralUtility::getIndpEnv('REQUEST_URI')
72 ];
73 $url = BackendUtility::getModuleUrl('tce_db', $urlParameters) . BackendUtility::getUrlToken('tceAction');
74
75 return '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" onclick="return confirm(' .
76 GeneralUtility::quoteJSvalue(LocalizationUtility::translate('confirm', 'beuser', array($backendUser->getUserName()))) .
77 ')">' . IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
78 }
79
80 }