‪TYPO3CMS  ‪main
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 
27 
34 {
40  protected ‪$defaultFieldInformation = [
41  'tcaDescription' => [
42  'renderType' => 'tcaDescription',
43  ],
44  ];
45 
46  public function ‪__construct(
47  private readonly ‪FlashMessageService $flashMessageService,
48  private readonly ‪StorageRepository $storageRepository,
49  ) {}
50 
58  public function ‪render(): array
59  {
60  $row = $this->data['databaseRow'];
61  $parameterArray = $this->data['parameterArray'];
62  $isPublic = (bool)‪$GLOBALS['TCA']['sys_file_storage']['columns']['is_public']['config']['default'];
63 
64  if ($this->data['command'] === 'edit') {
65  // Make sure the storage object can be retrieved which is not the case when new storage.
66  $lang = $this->‪getLanguageService();
67  $defaultFlashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier();
68  try {
69  $storage = $this->storageRepository->findByUid((int)$row['uid']);
70  $storageRecord = $storage->getStorageRecord();
71  $isPublic = $storage->isPublic() && $storageRecord['is_public'];
72 
73  // Display a warning to the BE User in case settings is not inline with storage capability.
74  if ($storageRecord['is_public'] && !$storage->isPublic()) {
75  $message = GeneralUtility::makeInstance(
76  FlashMessage::class,
77  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.message.storage_is_no_public'),
78  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.header.storage_is_no_public'),
79  ContextualFeedbackSeverity::WARNING
80  );
81  $defaultFlashMessageQueue->enqueue($message);
82  }
83  } catch (InvalidPathException $e) {
84  $message = GeneralUtility::makeInstance(
85  FlashMessage::class,
86  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.message'),
87  $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.title'),
88  ContextualFeedbackSeverity::ERROR
89  );
90  $defaultFlashMessageQueue->enqueue($message);
91  }
92  }
93 
94  $isPublicAsString = $isPublic ? '1' : '0';
95  $fieldInformationResult = $this->‪renderFieldInformation();
96  $fieldInformationHtml = $fieldInformationResult['html'];
97  $resultArray = $this->‪initializeResultArray();
98  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
99 
100  $checkboxParameters = $this->‪checkBoxParams(
101  $parameterArray['itemFormElName'],
102  $isPublic ? 1 : 0,
103  0,
104  1,
105  $parameterArray['fieldChangeFunc'] ?? []
106  );
107  $checkboxId = htmlspecialchars(‪StringUtility::getUniqueId('formengine-fal-is-public-'));
108  $html = [];
109  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
110  $html[] = $fieldInformationHtml;
111  $html[] = '<div class="form-wizards-wrap">';
112  $html[] = '<div class="form-wizards-element">';
113  $html[] = '<div class="form-check form-switch">';
114  $html[] = '<input type="checkbox"';
115  $html[] = ' class="form-check-input"';
116  $html[] = ' value="1"';
117  $html[] = ' data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName']) . '"';
118  $html[] = ' id="' . $checkboxId . '"';
119  $html[] = $checkboxParameters;
120  $html[] = $isPublic ? ' checked="checked"' : '';
121  $html[] = '/>';
122  $html[] = '<label class="form-check-label" for="' . $checkboxId . '">';
123  $html[] = $this->‪appendValueToLabelInDebugMode('', $isPublicAsString);
124  $html[] = '</label>';
125  $html[] = '<input type="hidden"';
126  $html[] = ' name="' . htmlspecialchars($parameterArray['itemFormElName']) . '"';
127  $html[] = ' value="' . $isPublicAsString . '"';
128  $html[] = ' />';
129  $html[] = '</div>';
130  $html[] = '</div>';
131  $html[] = '</div>';
132  $html[] = '</div>';
133  $resultArray['html'] = $this->‪wrapWithFieldsetAndLegend(implode(LF, $html));
134  return $resultArray;
135  }
136 }
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:73
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:104
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement\__construct
‪__construct(private readonly FlashMessageService $flashMessageService, private readonly StorageRepository $storageRepository,)
Definition: UserSysFileStorageIsPublicElement.php:45
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement
Definition: UserSysFileStorageIsPublicElement.php:34
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:37
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:16
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\wrapWithFieldsetAndLegend
‪wrapWithFieldsetAndLegend(string $innerHTML)
Definition: AbstractFormElement.php:133
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\getLanguageService
‪getLanguageService()
Definition: AbstractFormElement.php:456
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:38
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\appendValueToLabelInDebugMode
‪appendValueToLabelInDebugMode(string|int $label, string|int $value)
Definition: AbstractFormElement.php:447
‪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:383
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement\render
‪array render()
Definition: UserSysFileStorageIsPublicElement.php:57
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Core\Resource\Exception\InvalidPathException
Definition: InvalidPathException.php:23
‪TYPO3\CMS\Backend\Form\Element\UserSysFileStorageIsPublicElement\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: UserSysFileStorageIsPublicElement.php:39
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77