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\Localization\LanguageService
;
18 use TYPO3\CMS\Core\Messaging\FlashMessage
;
19 use TYPO3\CMS\Core\Messaging\FlashMessageQueue
;
20 use TYPO3\CMS\Core\Messaging\FlashMessageService
;
21 use TYPO3\CMS\Core\
Resource\Exception\InvalidPathException
;
22 use TYPO3\CMS\Core\
Resource\ResourceFactory
;
23 use TYPO3\CMS\Core\Utility\GeneralUtility
;
26 * Utility class to render capabilities of the storage.
28 class UserStorageCapabilityService
31 * UserFunc function for rendering field "is_public".
32 * There are some edge cases where "is_public" can never be marked as true in the BE,
33 * for instance for storage located outside the document root or
34 * for storages driven by special driver such as Flickr, ...
36 * @param array $propertyArray the array with additional configuration options.
39 public function renderIsPublic(array $propertyArray)
41 $isPublic = $GLOBALS['TCA']['sys_file_storage']['columns']['is_public']['config']['default'];
42 $fileRecord = $propertyArray['row'];
44 // Makes sure the storage object can be retrieved which is not the case when new storage.
45 if ((int)$propertyArray['row']['uid'] > 0) {
46 /** @var LanguageService $lang */
47 $lang = $GLOBALS['LANG'];
48 /** @var $flashMessageService FlashMessageService */
49 $flashMessageService = GeneralUtility
::makeInstance(FlashMessageService
::class);
50 /** @var $defaultFlashMessageQueue FlashMessageQueue */
51 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
53 $storage = ResourceFactory
::getInstance()->getStorageObject($fileRecord['uid']);
54 $storageRecord = $storage->getStorageRecord();
55 $isPublic = $storage->isPublic() && $storageRecord['is_public'];
56 } catch (InvalidPathException
$e) {
57 $message = GeneralUtility
::makeInstance(
59 $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.message'),
60 $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.title'),
63 $defaultFlashMessageQueue->enqueue($message);
66 // Display a warning to the BE User in case settings is not inline with storage capability.
67 if ($storageRecord['is_public'] && !$storage->isPublic()) {
68 $message = GeneralUtility
::makeInstance(
70 $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.message.storage_is_no_public'),
71 $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.header.storage_is_no_public'),
74 $defaultFlashMessageQueue->enqueue($message);
78 return $this->renderFileInformationContent($fileRecord, $isPublic);
82 * Renders a HTML block containing the checkbox for field "is_public".
84 * @param array $fileRecord
85 * @param bool $isPublic
88 protected function renderFileInformationContent(array $fileRecord, $isPublic)
91 <div class="t3-form-field-item">
92 <div class="checkbox">
94 <input name="data[sys_file_storage][{uid}][is_public]" value="0" type="hidden">
95 <input class="checkbox" value="1" name="data[sys_file_storage][{uid}][is_public]_0" type="checkbox" %s>
102 $isPublic ?
'checked="checked"' : ''
105 return str_replace('{uid}', $fileRecord['uid'], $content);