Skip to content

Commit ac9ae99

Browse files
committed
[FEATURE] Allow editors to choose whether attachments are sent
https://projekte.in2code.de/issues/66793
1 parent 627f533 commit ac9ae99

File tree

8 files changed

+139
-7
lines changed

8 files changed

+139
-7
lines changed

.project/tests/phpstan-baseline.neon

+5
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,11 @@ parameters:
34053405
count: 1
34063406
path: ../../Classes/UserFunc/DateConverter.php
34073407

3408+
-
3409+
message: "#^Method In2code\\\\Powermail\\\\UserFunc\\\\TestForFeature\\:\\:isFeatureEnabled\\(\\) has parameter \\$arguments with no value type specified in iterable type array\\.$#"
3410+
count: 1
3411+
path: ../../Classes/UserFunc/TestForFeature.php
3412+
34083413
-
34093414
message: "#^Method In2code\\\\Powermail\\\\Utility\\\\ArrayUtility\\:\\:arrayMergeRecursiveOverrule\\(\\) has parameter \\$firstArray with no value type specified in iterable type array\\.$#"
34103415
count: 1

.project/typo3/additional.php

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
'sitename' => 'LOKAL: ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],
5252
'displayErrors' => 1,
5353
'enableDeprecationLog' => 'file',
54+
'features' => [
55+
'powermailEditorsAreAllowedToSendAttachments' => true,
56+
],
5457
'systemLogLevel' => 0,
5558
'devIPmask' => '*',
5659
'clearCacheSystem' => 1,

Classes/UserFunc/TestForFeature.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace In2code\Powermail\UserFunc;
6+
7+
use TYPO3\CMS\Core\Configuration\Features;
8+
use TYPO3\CMS\Core\Utility\GeneralUtility;
9+
10+
class TestForFeature
11+
{
12+
public function isFeatureEnabled(array $arguments = []): bool
13+
{
14+
$features = GeneralUtility::makeInstance(Features::class);
15+
if ($features->isFeatureEnabled($arguments['conditionParameters'][0])) {
16+
return true;
17+
}
18+
return false;
19+
}
20+
}

Classes/Utility/ConfigurationUtility.php

+18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
88
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
99
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
10+
use TYPO3\CMS\Core\Configuration\Features;
1011
use TYPO3\CMS\Core\Core\Environment;
1112
use TYPO3\CMS\Core\Utility\ArrayUtility as CoreArrayUtility;
1213
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -205,19 +206,36 @@ public static function testGdExtension(): void
205206
* Merges Flexform, TypoScript and Extension Manager Settings
206207
* Note: If FF value is empty, we want the TypoScript value instead
207208
*
209+
* ToDo v14: Maybe drop this method completely and stick to TYPO3 default behavior ore use the extbase option;
210+
* see EXT:news -- overrideFlexFormsIfEmpty
211+
* see Core:Extbase -- ignoreFlexFormSettingsIfEmpty
212+
*
208213
* @param array $settings All settings
209214
* @param string $typoScriptLevel Startpoint
210215
* @return array
211216
*/
212217
public static function mergeTypoScript2FlexForm(array $settings, string $typoScriptLevel = 'setup'): array
213218
{
219+
$originalSettings = $settings;
214220
if (array_key_exists($typoScriptLevel, $settings) && array_key_exists('flexform', $settings)) {
215221
$settings = ArrayUtility::arrayMergeRecursiveOverrule(
216222
(array)$settings[$typoScriptLevel],
217223
(array)$settings['flexform'],
218224
false,
219225
false
220226
);
227+
228+
// ToDo: remove for TYPO3 v14 compatible version
229+
// Reason for this part is, the `emptyValuesOverride = true` in the arrayMergeRecursiveOverrule from above
230+
$features = GeneralUtility::makeInstance(Features::class);
231+
if ($features->isFeatureEnabled('powermailEditorsAreAllowedToSendAttachments')) {
232+
if (isset($originalSettings['flexform']['receiver']['attachment'])) {
233+
$settings['receiver']['attachment'] = $originalSettings['flexform']['receiver']['attachment'];
234+
}
235+
if (isset($originalSettings['flexform']['sender']['attachment'])) {
236+
$settings['sender']['attachment'] = $originalSettings['flexform']['sender']['attachment'];
237+
}
238+
}
221239
}
222240
return $settings;
223241
}

Configuration/FlexForms/FlexformPi1.xml

+20-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,16 @@
211211
<enableRichtext>1</enableRichtext>
212212
</config>
213213
</settings.flexform.receiver.body>
214-
</el>
214+
<settings.flexform.receiver.attachment>
215+
<displayCond>USER:In2code\Powermail\UserFunc\TestForFeature->isFeatureEnabled:powermailEditorsAreAllowedToSendAttachments</displayCond>
216+
<exclude>1</exclude>
217+
<label>LLL:EXT:powermail/Resources/Private/Language/locallang_db.xlf:flexform.receiver.attachment</label>
218+
<config>
219+
<type>check</type>
220+
<default>0</default>
221+
</config>
222+
</settings.flexform.receiver.attachment>
223+
</el>
215224
</ROOT>
216225
</receiver>
217226
<sender>
@@ -252,7 +261,16 @@
252261
<enableRichtext>1</enableRichtext>
253262
</config>
254263
</settings.flexform.sender.body>
255-
</el>
264+
<settings.flexform.sender.attachment>
265+
<displayCond>USER:In2code\Powermail\UserFunc\TestForFeature->isFeatureEnabled:powermailEditorsAreAllowedToSendAttachments</displayCond>
266+
<exclude>1</exclude>
267+
<label>LLL:EXT:powermail/Resources/Private/Language/locallang_db.xlf:flexform.sender.attachment</label>
268+
<config>
269+
<type>check</type>
270+
<default>0</default>
271+
</config>
272+
</settings.flexform.sender.attachment>
273+
</el>
256274
</ROOT>
257275
</sender>
258276
<thx>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# How to send attachments
2+
3+
## Defined by TypoScript
4+
5+
In versions < 12.5 it was only possible to define, whether attachments are sent or not, via TypoScript. This setting
6+
was used for all forms and plugins (unless you used conditions or set the value in the database).
7+
8+
```typo3_typoscript
9+
plugin.tx_powermail.settings.setup {
10+
reciever {
11+
attachment = {$plugin.tx_powermail.settings.receiver.attachment}
12+
}
13+
sender {
14+
attachment = {$plugin.tx_powermail.settings.sender.attachment}
15+
}
16+
}
17+
```
18+
19+
## Defined by editors
20+
21+
Since version 12.5 it is possible, that editors define, whether attachments should be sent or not. This feature is
22+
"hidden" behind a feature toggle and restrictive page tsconfig settings.
23+
24+
### Steps for activation
25+
26+
1) Activate the feature toggle in site settings
27+
28+
```php
29+
$GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['powermailEditorsAreAllowedToSendAttachments'] = true;
30+
```
31+
32+
2) Activate the fields in PageTSconfig
33+
34+
Due to security reasons these fields are hidden by default, so that the admin must take an additional step. Editors
35+
should not get more permissions, than necessary by a feature release. ;-)
36+
37+
```typo3_typoscript
38+
TCEFORM {
39+
tt_content {
40+
pi_flexform {
41+
powermail_pi1 {
42+
sender {
43+
settings\.flexform\.sender\.attachment {
44+
disabled = 0
45+
}
46+
}
47+
receiver {
48+
settings\.flexform\.receiver\.attachment {
49+
disabled = 0
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
```
57+

Resources/Private/Language/locallang_db.xlf

+6
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@
489489
<trans-unit id="flexform.receiver.body" resname="flexform.receiver.body">
490490
<source>Bodytext for Email to Receiver</source>
491491
</trans-unit>
492+
<trans-unit id="flexform.receiver.attachment" resname="flexform.receiver.attachment">
493+
<source>Send uploaded files to receiver</source>
494+
</trans-unit>
492495
<trans-unit id="flexform.sender" resname="flexform.sender">
493496
<source>Mail to User</source>
494497
</trans-unit>
@@ -504,6 +507,9 @@
504507
<trans-unit id="flexform.sender.body" resname="flexform.sender.body">
505508
<source>Bodytext for Email to Sender</source>
506509
</trans-unit>
510+
<trans-unit id="flexform.sender.attachment" resname="flexform.sender.attachment">
511+
<source>Send uploaded files to sender</source>
512+
</trans-unit>
507513
<trans-unit id="flexform.thx" resname="flexform.thx">
508514
<source>Submit Page</source>
509515
</trans-unit>

ext_localconf.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,17 @@
7878
);
7979

8080
/**
81-
* ContentElementWizard for Pi1
81+
* Include PageTSconfig
8282
*/
8383
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
8484
'@import \'EXT:powermail/Configuration/TSConfig/ContentElementWizard.typoscript\''
8585
);
86-
87-
/**
88-
* PageTSConfig for backend mod list
89-
*/
9086
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
9187
'@import \'EXT:powermail/Configuration/TSConfig/WebList.typoscript\''
9288
);
89+
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
90+
'@import \'EXT:powermail/Configuration/TSConfig/EditorsSendAttachments.typoscript\''
91+
);
9392

9493
/**
9594
* Hook for initially filling the marker field in backend
@@ -141,4 +140,10 @@
141140
= \In2code\Powermail\Update\PowermailPermissionUpdater::class;
142141
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['powermailPermissionSubmodulesUpdater']
143142
= \In2code\Powermail\Update\PowermailPermissionSubmoduleUpdater::class;
143+
144+
/**
145+
* Feature toggle
146+
* ToDo: remove for TYPO3 v14 compatible version
147+
*/
148+
$GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['powermailEditorsAreAllowedToSendAttachments'] ??= false;
144149
});

0 commit comments

Comments
 (0)