[TASK] Move HTML generation in RemoveUserViewHelper to the view 33/55733/5
authorGeorg Ringer <georg.ringer@gmail.com>
Thu, 15 Feb 2018 12:42:40 +0000 (13:42 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 17 Feb 2018 19:39:21 +0000 (20:39 +0100)
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>
typo3/sysext/beuser/Classes/Controller/BackendUserController.php
typo3/sysext/beuser/Classes/ViewHelpers/RemoveUserViewHelper.php
typo3/sysext/beuser/Resources/Private/Partials/BackendUser/IndexListRow.html
typo3/sysext/beuser/Resources/Private/Partials/BackendUser/PaginatedListWidget.html
typo3/sysext/beuser/Resources/Private/Partials/BackendUser/PaginatedListWidgetBody.html
typo3/sysext/beuser/Resources/Private/Partials/BackendUserGroup/PaginatedListWidgetBody.html
typo3/sysext/beuser/Resources/Private/Templates/BackendUser/Index.html

index 1e3a237..b3e3425 100644 (file)
@@ -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) : '');
     }
 
index 1337065..254d030 100644 (file)
@@ -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
  */
@@ -35,13 +31,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
      */
     public function initializeArguments()
@@ -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);
     }
 }
index a33f43b..fec20ab 100644 (file)
                                        </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>
index 598ecaa..a5f11ea 100644 (file)
@@ -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>
index e16b5d9..d1d812f 100644 (file)
@@ -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>
index 2982a43..476d660 100644 (file)
@@ -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>
index 279f2e8..6adad08 100644 (file)
@@ -8,7 +8,6 @@
 </f:section>
 
 <f:section name="content">
-
        <f:comment>
                Listing of users on compare list
        </f:comment>