4894d38cbdbabb0714c3118b629ab0f89dd932bc
[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 * @param \TYPO3\CMS\Backend\Form\FormEngine $tceformsObj the TCEforms parent object
32 * @return string
33 */
34 public function renderIsPublic(array $propertyArray, \TYPO3\CMS\Backend\Form\FormEngine $tceformsObj) {
35
36 $isPublic = $GLOBALS['TCA']['sys_file_storage']['columns']['is_public']['config']['default'];
37 $fileRecord = $propertyArray['row'];
38
39 // Makes sure the storage object can be retrieved which is not the case when new storage.
40 if ((int)$propertyArray['row']['uid'] > 0) {
41 $storage = ResourceFactory::getInstance()->getStorageObject($fileRecord['uid']);
42 $storageRecord = $storage->getStorageRecord();
43 $isPublic = $storage->isPublic();
44
45 // Display a warning to the BE User in case settings is not inline with storage capability.
46 if ($storageRecord['is_public'] != $storage->isPublic()) {
47 $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class,
48 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.message.storage_is_no_public'),
49 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.header.storage_is_no_public'),
50 \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
51 );
52
53 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
54 $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
55 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
56 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
57 $defaultFlashMessageQueue->enqueue($message);
58 }
59 }
60
61 return $this->renderFileInformationContent($fileRecord, $isPublic);
62 }
63
64 /**
65 * Renders a HTML block containing the checkbox for field "is_public".
66 *
67 * @param array $fileRecord
68 * @param bool $isPublic
69 * @return string
70 */
71 protected function renderFileInformationContent(array $fileRecord, $isPublic) {
72 $template = '
73 <div class="t3-form-field-item">
74 <input name="data[sys_file_storage][{uid}][is_public]" value="0" type="hidden">
75 <input class="checkbox" value="1" name="data[sys_file_storage][{uid}][is_public]_0" type="checkbox" %s>
76 </div>';
77
78 $content = sprintf($template,
79 $isPublic ? 'checked="checked"' : ''
80 );
81
82 return str_replace('{uid}', $fileRecord['uid'], $content);
83 }
84
85 }