[BUGFIX] Storage doesn't save is_public anymore
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Service / UserStorageCapabilityService.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Service;
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\Core\Resource\ResourceFactory;
18
19 /**
20 * Utility class to render capabilities of the storage.
21 */
22 class UserStorageCapabilityService {
23
24 /**
25 * UserFunc function for rendering field "is_public".
26 * There are some edge cases where "is_public" can never be marked as true in the BE,
27 * for instance for storage located outside the document root or
28 * for storages driven by special driver such as Flickr, ...
29 *
30 * @param array $propertyArray the array with additional configuration options.
31 * @return string
32 */
33 public function renderIsPublic(array $propertyArray) {
34
35 $isPublic = $GLOBALS['TCA']['sys_file_storage']['columns']['is_public']['config']['default'];
36 $fileRecord = $propertyArray['row'];
37
38 // Makes sure the storage object can be retrieved which is not the case when new storage.
39 if ((int)$propertyArray['row']['uid'] > 0) {
40 $storage = ResourceFactory::getInstance()->getStorageObject($fileRecord['uid']);
41 $storageRecord = $storage->getStorageRecord();
42 $isPublic = $storage->isPublic() && $storageRecord['is_public'];
43
44 // Display a warning to the BE User in case settings is not inline with storage capability.
45 if ($storageRecord['is_public'] && !$storage->isPublic()) {
46 $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class,
47 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.message.storage_is_no_public'),
48 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.header.storage_is_no_public'),
49 \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
50 );
51
52 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
53 $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
54 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
55 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
56 $defaultFlashMessageQueue->enqueue($message);
57 }
58 }
59
60 return $this->renderFileInformationContent($fileRecord, $isPublic);
61 }
62
63 /**
64 * Renders a HTML block containing the checkbox for field "is_public".
65 *
66 * @param array $fileRecord
67 * @param bool $isPublic
68 * @return string
69 */
70 protected function renderFileInformationContent(array $fileRecord, $isPublic) {
71 $template = '
72 <div class="t3-form-field-item">
73 <div class="checkbox">
74 <label>
75 <input name="data[sys_file_storage][{uid}][is_public]" value="0" type="hidden">
76 <input class="checkbox" value="1" name="data[sys_file_storage][{uid}][is_public]_0" type="checkbox" %s>
77 </label>
78 </div>
79 </div>';
80
81 $content = sprintf($template,
82 $isPublic ? 'checked="checked"' : ''
83 );
84
85 return str_replace('{uid}', $fileRecord['uid'], $content);
86 }
87
88 }