‪TYPO3CMS  9.5
UserStorageCapabilityService.php
Go to the documentation of this file.
1 <?php
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 
24 
31 {
35  public function ‪__construct()
36  {
37  trigger_error('This class will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
38  }
39 
49  public function ‪renderIsPublic(array $propertyArray)
50  {
51  $isPublic = ‪$GLOBALS['TCA']['sys_file_storage']['columns']['is_public']['config']['default'];
52  $fileRecord = $propertyArray['row'];
53 
54  // Makes sure the storage object can be retrieved which is not the case when new storage.
55  if ((int)$propertyArray['row']['uid'] > 0) {
57  $lang = ‪$GLOBALS['LANG'];
59  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
61  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
62  try {
63  $storage = ‪ResourceFactory::getInstance()->‪getStorageObject($fileRecord['uid']);
64  $storageRecord = $storage->‪getStorageRecord();
65  $isPublic = $storage->isPublic() && $storageRecord['is_public'];
66  } catch (‪InvalidPathException $e) {
67  $message = GeneralUtility::makeInstance(
68  FlashMessage::class,
69  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.message'),
70  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.title'),
72  );
73  $defaultFlashMessageQueue->enqueue($message);
74  }
75 
76  // Display a warning to the BE User in case settings is not inline with storage capability.
77  if ($storageRecord['is_public'] && !$storage->isPublic()) {
78  $message = GeneralUtility::makeInstance(
79  FlashMessage::class,
80  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.message.storage_is_no_public'),
81  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.header.storage_is_no_public'),
83  );
84  $defaultFlashMessageQueue->enqueue($message);
85  }
86  }
87 
88  return $this->‪renderFileInformationContent($fileRecord, $isPublic);
89  }
90 
98  protected function ‪renderFileInformationContent(array $fileRecord, $isPublic)
99  {
100  $template = '
101  <div class="checkbox checkbox-type-toggle">
102  <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 />
103  <label class="checkbox-label" for="filestorage-ispublic">
104  <span class="checkbox-label-text">&nbsp;</span>
105  </label>
106  <input type="hidden" name="data[sys_file_storage][{uid}][is_public]" value="1">
107  </div>
108  ';
109 
110  $content = sprintf(
111  $template,
112  $isPublic ? 'checked="checked"' : ''
113  );
114 
115  return str_replace('{uid}', $fileRecord['uid'], $content);
116  }
117 }
‪TYPO3\CMS\Core\Resource\ResourceStorage\getStorageRecord
‪array getStorageRecord()
Definition: ResourceStorage.php:229
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Core\Resource\Service
Definition: FileProcessingService.php:2
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Resource\Service\UserStorageCapabilityService
Definition: UserStorageCapabilityService.php:31
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Resource\Service\UserStorageCapabilityService\__construct
‪__construct()
Definition: UserStorageCapabilityService.php:35
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Core\Resource\Service\UserStorageCapabilityService\renderFileInformationContent
‪string renderFileInformationContent(array $fileRecord, $isPublic)
Definition: UserStorageCapabilityService.php:98
‪TYPO3\CMS\Core\Resource\ResourceFactory\getStorageObject
‪ResourceStorage getStorageObject($uid, array $recordData=[], &$fileIdentifier=null)
Definition: ResourceFactory.php:131
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:25
‪TYPO3\CMS\Core\Resource\Exception\InvalidPathException
Definition: InvalidPathException.php:21
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:25
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Core\Resource\Service\UserStorageCapabilityService\renderIsPublic
‪string renderIsPublic(array $propertyArray)
Definition: UserStorageCapabilityService.php:49