[FEATURE] Add delete button in file list 55/19155/4
authorBenjamin Mack <benni@typo3.org>
Thu, 21 Mar 2013 21:13:56 +0000 (22:13 +0100)
committerBenjamin Mack <benni@typo3.org>
Sun, 24 Mar 2013 09:29:01 +0000 (10:29 +0100)
Currently it is not possible to delete a file or folder
in the file list. Additionally, there is translation and
error handling missing. The patch adds the trash
icon to the file list (if the user has the right) and
adds error and success messages.

Releases: 6.1, 6.0
Resolves: #44288
Change-Id: I0f5be642054819a4f01c5e70590e1da455b92af6
Reviewed-on: https://review.typo3.org/19155
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php
typo3/sysext/filelist/Classes/FileList.php
typo3/sysext/lang/locallang_core.xlf

index ed9e269..dc1d5f8 100644 (file)
@@ -286,8 +286,10 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
         * @param string $redirect Redirect URL (for creating link in message)
         * @return void
         * @todo Define visibility
+        * @deprecated since TYPO3 6.1, will be removed two versions later, use ->getErrorMessages directly instead
         */
        public function printLogErrorMessages($redirect = '') {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
                $this->getErrorMessages();
        }
 
@@ -400,13 +402,26 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                                $shortcutContent[] = '<a href="#" oncontextmenu="' . htmlspecialchars($onClick) . '" onclick="' . htmlspecialchars($onClick) . '">' . $icon . '</a>' . htmlspecialchars((\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($row['tablename'], $shortcutRecord) . '  [' . \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordPath($shortcutRecord['pid'], '', 80) . ']'));
                                        }
                                }
-                               $out = '<p>The file cannot be deleted since it is still used at the following places:<br />' . implode('<br />', $shortcutContent) . '</p>';
-                               $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_flashMessage', $out, 'File not deleted', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, TRUE);
+
+                               // render a message that the file could not be deleted
+                               $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                                       '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                                       sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotDeletedHasReferences'), $fileObject->getName()) . '<br />' . implode('<br />', $shortcutContent),
+                                       $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotDeletedHasReferences'),
+                                       \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, TRUE);
                                \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($flashMessage);
-                               return;
                        } else {
                                try {
                                        $result = $fileObject->delete();
+
+                                       // show the user that the file was deleted
+                                       $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                                               '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                                               sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileDeleted'), $fileObject->getName()),
+                                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileDeleted'),
+                                               \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE);
+                                       \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($flashMessage);
+
                                } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
                                        $this->writelog(4, 1, 112, 'You are not allowed to access the file', array($fileObject->getIdentifier()));
                                } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
@@ -420,7 +435,28 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                } else {
                        try {
                                /** @var $fileObject \TYPO3\CMS\Core\Resource\FolderInterface */
-                               $result = $fileObject->delete(TRUE);
+                               if ($fileObject->getFileCount() > 0) {
+                                       // render a message that the folder could not be deleted because it still contains files
+                                       $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                                               '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                                               sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderNotDeletedHasFiles'), $fileObject->getName()),
+                                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderNotDeletedHasFiles'),
+                                               \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, TRUE);
+                                       \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($flashMessage);
+
+                               } else {
+                                       $result = $fileObject->delete(TRUE);
+
+                                       // notify the user that the folder was deleted
+                                       $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                                               '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                                               sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderDeleted'), $fileObject->getName()),
+                                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderDeleted'),
+                                               \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE);
+                                       \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($flashMessage);
+                               }
+
+
                        } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
                                $this->writelog(4, 1, 123, 'You are not allowed to access the directory', array($fileObject->getIdentifier()));
                        } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
index 7c6b82d..280dd3a 100644 (file)
@@ -729,6 +729,29 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                        $infoOnClick = 'top.launchView( \'_FILE\', \'' . $fullIdentifier . '\');return false;';
                }
                $cells['info'] = '<a href="#" onclick="' . $infoOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.info') . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-dialog-information') . '</a>';
+
+               // delete the file
+               if ($fileOrFolderObject->checkActionPermission('remove')) {
+                       $identifier = $fileOrFolderObject->getIdentifier();
+                       if ($fileOrFolderObject instanceof TYPO3\CMS\Core\Resource\Folder) {
+                               $referenceCountText = \TYPO3\CMS\Backend\Utility\BackendUtility::referenceCount('_FILE', $identifier, ' (There are %s reference(s) to this folder!)');
+                       } else {
+                               $referenceCountText = \TYPO3\CMS\Backend\Utility\BackendUtility::referenceCount('sys_file', $identifier, ' (There are %s reference(s) to this file!)');
+                       }
+
+                       if ($GLOBALS['BE_USER']->jsConfirmation(4)) {
+                               $confirmationCheck = 'confirm(' . $GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.delete'), basename($identifier)) . $referenceCountText) . ')';
+                       } else {
+                               $confirmationCheck = '1 == 1';
+                       }
+
+                       $removeOnClick = 'if (' . $confirmationCheck . ') { top.content.list_frame.location.href=top.TS.PATH_typo3+\'tce_file.php?file[delete][0][data]=' . rawurlencode($fileOrFolderObject->getCombinedIdentifier()) . '&vC=' . $GLOBALS['BE_USER']->veriCode() . '&redirect=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);};';
+
+                       $cells['delete'] = '<a href="#" onclick="' . htmlspecialchars($removeOnClick) . '"  title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.delete') . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
+               } else {
+                       $cells['delete'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty');
+               }
+
                // Hook for manipulating edit icons.
                if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
                        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
index 810f8ad..90b6219 100644 (file)
@@ -645,6 +645,31 @@ Would you like to save now in order to refresh the display?</source>
                        <trans-unit id="rm.delete" xml:space="preserve">
                                <source>Delete</source>
                        </trans-unit>
+                       <trans-unit id="message.header.fileNotDeletedHasReferences" xml:space="preserve">
+                               <source>File not deleted</source>
+                       </trans-unit>
+                       <trans-unit id="message.description.fileNotDeletedHasReferences" xml:space="preserve">
+                               <source>The file cannot be deleted since it is still used at the following places:</source>
+                       </trans-unit>
+                       <trans-unit id="message.header.fileDeleted" xml:space="preserve">
+                               <source>File deleted</source>
+                       </trans-unit>
+                       <trans-unit id="message.description.fileDeleted" xml:space="preserve">
+                               <source>The file "%s" was successfully deleted.</source>
+                       </trans-unit>
+                       <trans-unit id="message.header.folderDeleted" xml:space="preserve">
+                               <source>Folder deleted</source>
+                       </trans-unit>
+                       <trans-unit id="message.description.folderDeleted" xml:space="preserve">
+                               <source>The folder "%s" was successfully deleted.</source>
+                       </trans-unit>
+                       <trans-unit id="message.header.folderNotDeletedHasFiles" xml:space="preserve">
+                               <source>Folder not deleted</source>
+                       </trans-unit>
+                       <trans-unit id="message.description.folderNotDeletedHasFiles" xml:space="preserve">
+                               <source>The folder cannot be deleted since it still contains files.</source>
+                       </trans-unit>
+
                        <trans-unit id="buttons.logout" xml:space="preserve">
                                <source>Logout</source>
                        </trans-unit>