Completed
Push — payment ( a2694a )
by Torben
42:06
created

processDatamap_postProcessFieldArray()   C

Complexity

Conditions 10
Paths 8

Size

Total Lines 53
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 53
rs 6.5333
cc 10
eloc 37
nc 8
nop 5

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace DERHANSEN\SfEventMgt\Hooks;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19
/**
20
 * Hooks for DataHandler
21
 *
22
 * @author Torben Hansen <[email protected]>
23
 */
24
class DataHandlerHooks
25
{
26
27
    /**
28
     * Checks if the fields defined in $checkFields are set in the data-array of pi_flexform.
29
     * If a field is present and contains an empty value, the field is unset.
30
     *
31
     * Structure of the checkFields array:
32
     *
33
     * array('sheet' => array('field1', 'field2'));
34
     *
35
     * @param string $status
36
     * @param string $table
37
     * @param string $id
38
     * @param array $fieldArray
39
     * @param \TYPO3\CMS\Core\DataHandling\DataHandler $reference
40
     *
41
     * @return void
42
     */
43
    public function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, &$reference)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $reference is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Method name "DataHandlerHooks::processDatamap_postProcessFieldArray" is not in camel caps format
Loading history...
44
    {
45
        if ($table === 'tt_content' && $status == 'update' && isset($fieldArray['pi_flexform'])) {
46
            $checkFields = [
47
                'notification' => [
48
                    'settings.notification.senderEmail',
49
                    'settings.notification.senderName',
50
                    'settings.notification.adminEmail',
51
                    'settings.notification.registrationNew.userSubject',
52
                    'settings.notification.registrationNew.adminSubject',
53
                    'settings.notification.registrationConfirmed.userSubject',
54
                    'settings.notification.registrationConfirmed.adminSubject',
55
                    'settings.notification.registrationCancelled.userSubject',
56
                    'settings.notification.registrationCancelled.adminSubject',
57
                ],
58
                'sDEF' => [
59
                    'settings.templateLayout',
60
                    'settings.detailPid',
61
                    'settings.listPid',
62
                    'settings.registrationPid',
63
                    'settings.displayMode',
64
                    'settings.orderField',
65
                    'settings.orderDirection',
66
                    'settings.topEventRestriction',
67
                    'settings.queryLimit',
68
                    'settings.category',
69
                    'settings.restrictForeignRecordsToStoragePage',
70
                    'settings.storagePage',
71
                    'settings.registration.requiredFields'
72
                ]
73
            ];
74
75
            $flexformData = GeneralUtility::xml2array($fieldArray['pi_flexform']);
76
            foreach ($checkFields as $sheet => $fields) {
77
                foreach ($fields as $field) {
78
                    if (isset($flexformData['data'][$sheet]['lDEF'][$field]['vDEF']) &&
79
                        $flexformData['data'][$sheet]['lDEF'][$field]['vDEF'] === ''
80
                    ) {
81
                        unset($flexformData['data'][$sheet]['lDEF'][$field]);
82
                    }
83
                }
84
85
                // If remaining sheet does not contain fields, then remove the sheet
86
                if (isset($flexformData['data'][$sheet]['lDEF']) && $flexformData['data'][$sheet]['lDEF'] === []) {
87
                    unset($flexformData['data'][$sheet]);
88
                }
89
            }
90
91
            /** @var \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools $flexFormTools */
92
            $flexFormTools = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools');
93
            $fieldArray['pi_flexform'] = $flexFormTools->flexArray2Xml($flexformData, true);
94
        }
95
    }
96
97
}
98