‪TYPO3CMS  9.5
UserSysFileStorageIsPublicElement.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
24 
31 {
37  protected ‪$defaultFieldInformation = [
38  'tcaDescription' => [
39  'renderType' => 'tcaDescription',
40  ],
41  ];
42 
50  public function ‪render(): array
51  {
52  $row = $this->data['databaseRow'];
53  $parameterArray = $this->data['parameterArray'];
54  $isPublic = (bool)‪$GLOBALS['TCA']['sys_file_storage']['columns']['is_public']['config']['default'];
55 
56  if ($this->data['command'] === 'edit') {
57  // Make sure the storage object can be retrieved which is not the case when new storage.
58  $lang = $this->‪getLanguageService();
59  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
60  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
61  try {
62  $storage = ‪ResourceFactory::getInstance()->‪getStorageObject((int)$row['uid']);
63  $storageRecord = $storage->‪getStorageRecord();
64  $isPublic = $storage->isPublic() && $storageRecord['is_public'];
65 
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(
69  FlashMessage::class,
70  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.message.storage_is_no_public'),
71  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.header.storage_is_no_public'),
73  );
74  $defaultFlashMessageQueue->enqueue($message);
75  }
76  } catch (‪InvalidPathException $e) {
77  $message = GeneralUtility::makeInstance(
78  FlashMessage::class,
79  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.message'),
80  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.title'),
82  );
83  $defaultFlashMessageQueue->enqueue($message);
84  }
85  }
86 
87  $isPublicAsString = $isPublic ? '1' : '0';
88  $fieldInformationResult = $this->‪renderFieldInformation();
89  $fieldInformationHtml = $fieldInformationResult['html'];
90  $resultArray = $this->‪mergeChildReturnIntoExistingResult($this->‪initializeResultArray(), $fieldInformationResult, false);
91 
92  $checkboxParameters = $this->‪checkBoxParams($parameterArray['itemFormElName'], $isPublic, 0, 1, implode('', $parameterArray['fieldChangeFunc']));
93  $checkboxId = $parameterArray['itemFormElID'] . '_1';
94  $html = [];
95  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
96  $html[] = $fieldInformationHtml;
97  $html[] = '<div class="form-wizards-wrap">';
98  $html[] = '<div class="form-wizards-element">';
99  $html[] = '<div class="checkbox checkbox-type-toggle">';
100  $html[] = '<input type="checkbox"';
101  $html[] = ' class="checkbox-input"';
102  $html[] = ' value="1"';
103  $html[] = ' data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName'], ENT_QUOTES) . '"';
104  $html[] = ' id="' . htmlspecialchars($checkboxId, ENT_QUOTES) . '"';
105  $html[] = $checkboxParameters;
106  $html[] = $isPublic ? ' checked="checked"' : '';
107  $html[] = '/>';
108  $html[] = '<label class="checkbox-label" for="' . htmlspecialchars($checkboxId, ENT_QUOTES) . '">';
109  $html[] = '<span class="checkbox-label-text">' . $this->‪appendValueToLabelInDebugMode('&nbsp;', $isPublicAsString) . '</span>';
110  $html[] = '</label>';
111  $html[] = '<input type="hidden"';
112  $html[] = ' name="' . htmlspecialchars($parameterArray['itemFormElName'], ENT_QUOTES) . '"';
113  $html[] = ' value="' . $isPublicAsString . '"';
114  $html[] = ' />';
115  $html[] = '</div>';
116  $html[] = '</div>';
117  $html[] = '</div>';
118  $html[] = '</div>';
119  $resultArray['html'] = implode(LF, $html);
120  return $resultArray;
121  }
122 
126  protected function ‪getLanguageService(): ‪LanguageService
127  {
128  return ‪$GLOBALS['LANG'];
129  }
130 }
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement\getLanguageService
‪LanguageService getLanguageService()
Definition: UserSysFileStorageIsPublicElement.php:125
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:71
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:115
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:88
‪TYPO3\CMS\Core\Resource\ResourceStorage\getStorageRecord
‪array getStorageRecord()
Definition: ResourceStorage.php:229
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\appendValueToLabelInDebugMode
‪string int appendValueToLabelInDebugMode($label, $value)
Definition: AbstractFormElement.php:377
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement
Definition: UserSysFileStorageIsPublicElement.php:31
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:31
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:2
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪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\Backend\Form\Element\UserSysFileStorageIsPublicElement\render
‪array render()
Definition: UserSysFileStorageIsPublicElement.php:49
‪TYPO3\CMS\Core\Resource\Exception\InvalidPathException
Definition: InvalidPathException.php:21
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: UserSysFileStorageIsPublicElement.php:36
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:25
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\checkBoxParams
‪string checkBoxParams($itemName, $formElementValue, $checkbox, $checkboxesCount, $additionalJavaScript='')
Definition: AbstractFormElement.php:321