‪TYPO3CMS  11.5
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(StorageRepository::class)->findByUid((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(
95  $parameterArray['itemFormElName'],
96  $isPublic ? 1 : 0,
97  0,
98  1,
99  $parameterArray['fieldChangeFunc'] ?? []
100  );
101  $checkboxId = $parameterArray['itemFormElID'] . '_1';
102  $html = [];
103  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
104  $html[] = $fieldInformationHtml;
105  $html[] = '<div class="form-wizards-wrap">';
106  $html[] = '<div class="form-wizards-element">';
107  $html[] = '<div class="form-check form-switch">';
108  $html[] = '<input type="checkbox"';
109  $html[] = ' class="form-check-input"';
110  $html[] = ' value="1"';
111  $html[] = ' data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName'], ENT_QUOTES) . '"';
112  $html[] = ' id="' . htmlspecialchars($checkboxId, ENT_QUOTES) . '"';
113  $html[] = $checkboxParameters;
114  $html[] = $isPublic ? ' checked="checked"' : '';
115  $html[] = '/>';
116  $html[] = '<label class="form-check-label" for="' . htmlspecialchars($checkboxId, ENT_QUOTES) . '">';
117  $html[] = '<span class="form-check-label-text">' . $this->‪appendValueToLabelInDebugMode('&nbsp;', $isPublicAsString) . '</span>';
118  $html[] = '</label>';
119  $html[] = '<input type="hidden"';
120  $html[] = ' name="' . htmlspecialchars($parameterArray['itemFormElName'], ENT_QUOTES) . '"';
121  $html[] = ' value="' . $isPublicAsString . '"';
122  $html[] = ' />';
123  $html[] = '</div>';
124  $html[] = '</div>';
125  $html[] = '</div>';
126  $html[] = '</div>';
127  $resultArray['html'] = implode(LF, $html);
128  return $resultArray;
129  }
130 
134  protected function ‪getLanguageService(): ‪LanguageService
135  {
136  return ‪$GLOBALS['LANG'];
137  }
138 }
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement\getLanguageService
‪LanguageService getLanguageService()
Definition: UserSysFileStorageIsPublicElement.php:133
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:76
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:120
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:91
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement
Definition: UserSysFileStorageIsPublicElement.php:33
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:35
‪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\StorageRepository
Definition: StorageRepository.php:38
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\checkBoxParams
‪string checkBoxParams(string $itemName, int $formElementValue, int $checkbox, int $checkboxesCount, array $fieldChangeFuncs=[], bool $invert=false)
Definition: AbstractFormElement.php:366
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\appendValueToLabelInDebugMode
‪string appendValueToLabelInDebugMode($label, $value)
Definition: AbstractFormElement.php:436
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement\render
‪array render()
Definition: UserSysFileStorageIsPublicElement.php:51
‪TYPO3\CMS\Core\Resource\Exception\InvalidPathException
Definition: InvalidPathException.php:23
‪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