1
|
|
|
<?php |
2
|
|
|
namespace SKYFILLERS\SfFilecollectionGallery\Hooks; |
3
|
|
|
/* |
4
|
|
|
* This file is part of the TYPO3 CMS project. |
5
|
|
|
* |
6
|
|
|
* It is free software; you can redistribute it and/or modify it under |
7
|
|
|
* the terms of the GNU General Public License, either version 2 |
8
|
|
|
* of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please read the |
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* The TYPO3 project - inspiring people to share! |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Hooks for DataHandler |
20
|
|
|
* |
21
|
|
|
* Idea to use Hook for flexform settings: |
22
|
|
|
* http://www.derhansen.de/2014/06/typo3-how-to-prevent-empty-flexform.html |
23
|
|
|
* |
24
|
|
|
* @author Jöran Kurschatke <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class DataHandlerHooks { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Checks if the fields defined in $checkFields are set |
30
|
|
|
* in the data-array of pi_flexform. |
31
|
|
|
* If a field is present and contains an empty value, the field is unset. |
32
|
|
|
* |
33
|
|
|
* Structure of the checkFields array: |
34
|
|
|
* |
35
|
|
|
* array('sheet' => array('field1', 'field2')); |
36
|
|
|
* |
37
|
|
|
* @param string $status The status |
38
|
|
|
* @param string $table The table |
39
|
|
|
* @param string $id The id |
40
|
|
|
* @param array $fieldArray The filedArray |
41
|
|
|
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $reference The reference |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, &$reference) { |
|
|
|
|
46
|
|
|
if ($table === 'tt_content' && $status == 'update' && isset($fieldArray['pi_flexform'])) { |
47
|
|
|
$checkFields = array( |
48
|
|
|
'sDEF' => array( |
49
|
|
|
'settings.imagesPerPage', |
50
|
|
|
'settings.numberOfPages' |
51
|
|
|
), |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$flexformData = GeneralUtility::xml2array($fieldArray['pi_flexform']); |
55
|
|
|
|
56
|
|
|
foreach ($checkFields as $sheet => $fields) { |
57
|
|
|
foreach ($fields as $field) { |
58
|
|
|
if (isset($flexformData['data'][$sheet]['lDEF'][$field]['vDEF']) && |
59
|
|
|
$flexformData['data'][$sheet]['lDEF'][$field]['vDEF'] === '') { |
60
|
|
|
unset($flexformData['data'][$sheet]['lDEF'][$field]); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// If remaining sheet does not contain fields, then remove the sheet |
65
|
|
|
if (isset($flexformData['data'][$sheet]['lDEF']) && $flexformData['data'][$sheet]['lDEF'] === array()) { |
66
|
|
|
unset($flexformData['data'][$sheet]); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the flexform tools |
72
|
|
|
* @var \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools $flexFormTools |
73
|
|
|
*/ |
74
|
|
|
$flexFormTools = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools'); |
75
|
|
|
$fieldArray['pi_flexform'] = $flexFormTools->flexArray2Xml($flexformData, TRUE); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.