Project

General

Profile

Typo3 V10 > V11 » History » Version 1

Enis Nuredini, 05.04.2023 10:11

1 1 Enis Nuredini
h1. Migration Typo3 v10 > v11
2
3
Some changes in php are needed to get QFQ work in v11.
4
5
h3. File ext_localconf.php
6
7
The configurePlugin block needs to be changed to following:
8
<pre>
9
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
10
    'IMATHUZH.qfq',
11
    'Qfq',
12
    [\IMATHUZH\Qfq\Controller\QfqController::class => 'show'],
13
    [\IMATHUZH\Qfq\Controller\QfqController::class => 'show'], // put here as well, if controller output must not be cached
14
    \TYPO3\CMS\Extbase\Utility\ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT
15
);
16
</pre>
17
18
19
h3. QFQ Class QfqController.php
20
21
Two new needed Classes needs to be linked:
22
<pre>
23
use Psr\Http\Message\ResponseInterface;
24
use TYPO3\CMS\Core\Http\HtmlResponse;
25
</pre>
26
27
Changes for the showAction() function:
28
<pre>
29
    public function showAction(): ResponseInterface {
30
31
        $html = '';
32
        $origErrorReporting = '';
33
        $flagOk = false;
34
35
        try {
36
            $contentObject = $this->configurationManager->getContentObject();
37
38
            // By T3 default 'E_NOTICE' is unset. E.g. 'Undefined Index' will throw an exception.
39
            // QFQ like to see those 'E_NOTICE'
40
            $origErrorReporting = error_reporting();
41
            error_reporting($origErrorReporting | E_NOTICE);
42
43
            $qfq = new QuickFormQuery($contentObject->data);
44
            $html = $qfq->process();
45
            $flagOk = true;
46
47
        } catch (\UserFormException $e) {
48
            $html = $e->formatMessage();
49
50
        } catch (\UserReportException $e) {
51
            $html = $e->formatMessage();
52
53
        } catch (\CodeException $e) {
54
            $html = $e->formatMessage();
55
56
        } catch (\DbException $e) {
57
            $html = $e->formatMessage();
58
59
        } catch (\ShellException $e) {
60
            $html = $e->formatMessage();
61
62
        } catch (\DownloadException $e) {
63
            $html = $e->formatMessage();
64
65
        } catch (\Exception $e) {
66
            $ee = new \UserReportException(json_encode([
67
                ERROR_MESSAGE_TO_USER => "Generic Exception: " . $e->getMessage(),
68
                ERROR_MESSAGE_TO_DEVELOPER => $e->getTraceAsString()]), E_ERROR);
69
            $html = $ee->formatMessage();
70
        } catch (\Throwable $e) {
71
            $ee = new \UserReportException(json_encode([
72
                ERROR_MESSAGE_TO_USER => "Generic Error: " . $e->getMessage(),
73
                ERROR_MESSAGE_TO_DEVELOPER => $e->getTraceAsString()]), E_ERROR);
74
            $html = $ee->formatMessage();
75
        }
76
77
        if (isset($e) && $e->getCode() == ERROR_QUIT_QFQ_REGULAR) {
78
            $flagOk = true;
79
        }
80
81
        if (!$flagOk) {
82
            $html = "<div class='alert alert-warning'>$html</div>";
83
        }
84
85
        // Restore has to be outside of try/catch - E_NOTICE needs to unset for further T3 handling after an QFQ Exception.
86
        error_reporting($origErrorReporting);
87
88
        $this->view->assign('qfqOutput', $html);
89
        $content = $this->view->render();
90
        
91
        return new HtmlResponse($content);
92
    }
93
</pre>
94
95
We see that the new Typo3 versions are waiting for returned HtmlResponse Objects.