2 namespace TYPO3\CMS\Core\
Resource\Service
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Imaging\Icon
;
18 use TYPO3\CMS\Core\Imaging\IconFactory
;
19 use TYPO3\CMS\Core\Localization\LanguageService
;
20 use TYPO3\CMS\Core\Messaging\FlashMessage
;
21 use TYPO3\CMS\Core\Messaging\FlashMessageQueue
;
22 use TYPO3\CMS\Core\Messaging\FlashMessageService
;
23 use TYPO3\CMS\Core\
Resource\Exception\InvalidPathException
;
24 use TYPO3\CMS\Core\
Resource\ResourceFactory
;
25 use TYPO3\CMS\Core\Utility\GeneralUtility
;
28 * Utility class to render capabilities of the storage.
30 class UserStorageCapabilityService
33 * UserFunc function for rendering field "is_public".
34 * There are some edge cases where "is_public" can never be marked as true in the BE,
35 * for instance for storage located outside the document root or
36 * for storages driven by special driver such as Flickr, ...
38 * @param array $propertyArray the array with additional configuration options.
41 public function renderIsPublic(array $propertyArray)
43 $isPublic = $GLOBALS['TCA']['sys_file_storage']['columns']['is_public']['config']['default'];
44 $fileRecord = $propertyArray['row'];
46 // Makes sure the storage object can be retrieved which is not the case when new storage.
47 if ((int)$propertyArray['row']['uid'] > 0) {
48 /** @var LanguageService $lang */
49 $lang = $GLOBALS['LANG'];
50 /** @var $flashMessageService FlashMessageService */
51 $flashMessageService = GeneralUtility
::makeInstance(FlashMessageService
::class);
52 /** @var $defaultFlashMessageQueue FlashMessageQueue */
53 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
55 $storage = ResourceFactory
::getInstance()->getStorageObject($fileRecord['uid']);
56 $storageRecord = $storage->getStorageRecord();
57 $isPublic = $storage->isPublic() && $storageRecord['is_public'];
58 } catch (InvalidPathException
$e) {
59 $message = GeneralUtility
::makeInstance(
61 $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.message'),
62 $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.title'),
65 $defaultFlashMessageQueue->enqueue($message);
68 // Display a warning to the BE User in case settings is not inline with storage capability.
69 if ($storageRecord['is_public'] && !$storage->isPublic()) {
70 $message = GeneralUtility
::makeInstance(
72 $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.message.storage_is_no_public'),
73 $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.header.storage_is_no_public'),
76 $defaultFlashMessageQueue->enqueue($message);
80 return $this->renderFileInformationContent($fileRecord, $isPublic);
84 * Renders a HTML block containing the checkbox for field "is_public".
86 * @param array $fileRecord
87 * @param bool $isPublic
90 protected function renderFileInformationContent(array $fileRecord, $isPublic)
92 $iconFactory = GeneralUtility
::makeInstance(IconFactory
::class);
93 $iconChecked = $iconFactory->getIcon('actions-check', Icon
::SIZE_SMALL
)->render('inline');
94 $iconUnchecked = $iconFactory->getIcon('empty-empty', Icon
::SIZE_SMALL
)->render('inline');
97 <div class="checkbox checkbox-type-icon-toggle">
98 <input type="checkbox" id="filestorage-ispublic" onclick="document.editform[\'data[sys_file_storage][{uid}][is_public]\'].value=this.checked?(document.editform[\'data[sys_file_storage][{uid}][is_public]\'].value|1):(document.editform[\'data[sys_file_storage][{uid}][is_public]\'].value&0);TBE_EDITOR.fieldChanged(\'sys_file_storage\',\'{uid}\',\'is_public\',\'data[sys_file_storage][{uid}][is_public]\');" class="checkbox-input" value="1" name="data[sys_file_storage][{uid}][is_public]_0" %s />
99 <label class="checkbox-label" for="filestorage-ispublic">
100 <span class="checkbox-label-icon">
101 <span class="checkbox-label-icon-checked">' . $iconChecked . '</span>
102 <span class="checkbox-label-icon-unchecked">' . $iconUnchecked . '</span>
104 <span class="checkbox-label-text"> </span>
106 <input type="hidden" name="data[sys_file_storage][{uid}][is_public]" value="1">
112 $isPublic ?
'checked="checked"' : ''
115 return str_replace('{uid}', $fileRecord['uid'], $content);