• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / typo3-form-consent / 13956821170

19 Mar 2025 09:12PM UTC coverage: 83.781% (-9.2%) from 93.012%
13956821170

Pull #354

github

web-flow
Merge b5968a39f into 881eb0c1f
Pull Request #354: Mark form finishers as approval/dismissal dependant via form editor

8 of 101 new or added lines in 4 files covered. (7.92%)

780 of 931 relevant lines covered (83.78%)

12.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

36.36
/Classes/Middleware/FormVariantMiddleware.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "form_consent".
7
 *
8
 * Copyright (C) 2021-2025 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Typo3FormConsent\Middleware;
25

26
use EliasHaeussler\Typo3FormConsent\Domain\Variants\ConsentVariantManager;
27
use Psr\Http\Message\ResponseInterface;
28
use Psr\Http\Message\ServerRequestInterface;
29
use Psr\Http\Server\MiddlewareInterface;
30
use Psr\Http\Server\RequestHandlerInterface;
31
use TYPO3\CMS\Core\Http\ApplicationType;
32
use TYPO3\CMS\Core\Http\Stream;
33

34
/**
35
 * Modify Form Editor output.
36
 */
37
class FormVariantMiddleware implements MiddlewareInterface
38
{
39
    public function __construct(protected ConsentVariantManager $consentVariantManager){}
5✔
40

41
    /**
42
     * @param ServerRequestInterface $request
43
     * @param RequestHandlerInterface $handler
44
     * @return ResponseInterface
45
     */
46
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
5✔
47
    {
48
        $response = $handler->handle($request);
5✔
49
        if (!$this->requestIsInFormEditor($request)) {
5✔
50
            return $response;
5✔
51
        }
NEW
52
        $body = $response->getBody();
×
NEW
53
        $body->rewind();
×
NEW
54
        $content = $response->getBody()->getContents();
×
NEW
55
        $contentArray = json_decode($content, true);
×
NEW
56
        $formDefinition = $contentArray['formDefinition'] ?? [];
×
NEW
57
        if (!empty($formDefinition)) {
×
NEW
58
            $formDefinition = $this->consentVariantManager->streamlineFormFinishers($formDefinition);
×
NEW
59
            $contentArray['formDefinition'] = $formDefinition;
×
NEW
60
            $newContent = json_encode($contentArray);
×
NEW
61
            $body = new Stream('php://temp', 'rw');
×
NEW
62
            $body->write($newContent);
×
NEW
63
            return $response->withBody($body);
×
64
        }
NEW
65
        return $response;
×
66
    }
67

68
    /**
69
     * @param ServerRequestInterface $request
70
     * @return bool
71
     */
72
    protected function requestIsInFormEditor(ServerRequestInterface $request): bool
5✔
73
    {
74
        if (!ApplicationType::fromRequest($request)->isBackend()) {
5✔
NEW
75
            return false;
×
76
        }
77
        return $request->getUri()->getPath() === '/typo3/module/manage/forms/FormEditor/saveForm';
5✔
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc