‪TYPO3CMS  10.4
UserSysFileStorageIsPublicElement.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
26 
33 {
39  protected ‪$defaultFieldInformation = [
40  'tcaDescription' => [
41  'renderType' => 'tcaDescription',
42  ],
43  ];
44 
52  public function ‪render(): array
53  {
54  $row = $this->data['databaseRow'];
55  $parameterArray = $this->data['parameterArray'];
56  $isPublic = (bool)‪$GLOBALS['TCA']['sys_file_storage']['columns']['is_public']['config']['default'];
57 
58  if ($this->data['command'] === 'edit') {
59  // Make sure the storage object can be retrieved which is not the case when new storage.
60  $lang = $this->‪getLanguageService();
61  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
62  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
63  try {
64  $storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject((int)$row['uid']);
65  $storageRecord = $storage->getStorageRecord();
66  $isPublic = $storage->isPublic() && $storageRecord['is_public'];
67 
68  // Display a warning to the BE User in case settings is not inline with storage capability.
69  if ($storageRecord['is_public'] && !$storage->isPublic()) {
70  $message = GeneralUtility::makeInstance(
71  FlashMessage::class,
72  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.message.storage_is_no_public'),
73  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.header.storage_is_no_public'),
75  );
76  $defaultFlashMessageQueue->enqueue($message);
77  }
78  } catch (‪InvalidPathException $e) {
79  $message = GeneralUtility::makeInstance(
80  FlashMessage::class,
81  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.message'),
82  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.title'),
84  );
85  $defaultFlashMessageQueue->enqueue($message);
86  }
87  }
88 
89  $isPublicAsString = $isPublic ? '1' : '0';
90  $fieldInformationResult = $this->‪renderFieldInformation();
91  $fieldInformationHtml = $fieldInformationResult['html'];
92  $resultArray = $this->‪mergeChildReturnIntoExistingResult($this->‪initializeResultArray(), $fieldInformationResult, false);
93 
94  $checkboxParameters = $this->‪checkBoxParams($parameterArray['itemFormElName'], $isPublic ? 1 : 0, 0, 1, implode('', $parameterArray['fieldChangeFunc']));
95  $checkboxId = $parameterArray['itemFormElID'] . '_1';
96  $html = [];
97  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
98  $html[] = $fieldInformationHtml;
99  $html[] = '<div class="form-wizards-wrap">';
100  $html[] = '<div class="form-wizards-element">';
101  $html[] = '<div class="checkbox checkbox-type-toggle">';
102  $html[] = '<input type="checkbox"';
103  $html[] = ' class="checkbox-input"';
104  $html[] = ' value="1"';
105  $html[] = ' data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName'], ENT_QUOTES) . '"';
106  $html[] = ' id="' . htmlspecialchars($checkboxId, ENT_QUOTES) . '"';
107  $html[] = $checkboxParameters;
108  $html[] = $isPublic ? ' checked="checked"' : '';
109  $html[] = '/>';
110  $html[] = '<label class="checkbox-label" for="' . htmlspecialchars($checkboxId, ENT_QUOTES) . '">';
111  $html[] = '<span class="checkbox-label-text">' . $this->‪appendValueToLabelInDebugMode('&nbsp;', $isPublicAsString) . '</span>';
112  $html[] = '</label>';
113  $html[] = '<input type="hidden"';
114  $html[] = ' name="' . htmlspecialchars($parameterArray['itemFormElName'], ENT_QUOTES) . '"';
115  $html[] = ' value="' . $isPublicAsString . '"';
116  $html[] = ' />';
117  $html[] = '</div>';
118  $html[] = '</div>';
119  $html[] = '</div>';
120  $html[] = '</div>';
121  $resultArray['html'] = implode(LF, $html);
122  return $resultArray;
123  }
124 
128  protected function ‪getLanguageService(): ‪LanguageService
129  {
130  return ‪$GLOBALS['LANG'];
131  }
132 }
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement\getLanguageService
‪LanguageService getLanguageService()
Definition: UserSysFileStorageIsPublicElement.php:127
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:72
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:116
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:90
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement
Definition: UserSysFileStorageIsPublicElement.php:33
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:32
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:16
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:30
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\appendValueToLabelInDebugMode
‪string appendValueToLabelInDebugMode($label, $value)
Definition: AbstractFormElement.php:378
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement\render
‪array render()
Definition: UserSysFileStorageIsPublicElement.php:51
‪TYPO3\CMS\Core\Resource\Exception\InvalidPathException
Definition: InvalidPathException.php:24
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: UserSysFileStorageIsPublicElement.php:38
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\checkBoxParams
‪string checkBoxParams($itemName, $formElementValue, $checkbox, $checkboxesCount, $additionalJavaScript='')
Definition: AbstractFormElement.php:322