1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2017 Romain CANON <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the TYPO3 Formz project. |
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU General Public License, either |
8
|
|
|
* version 3 of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, see: |
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Romm\Formz\AssetHandler\Css; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\AssetHandler\AbstractAssetHandler; |
17
|
|
|
use Romm\Formz\AssetHandler\Html\DataAttributesAssetHandler; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* This asset handler generates the CSS code which will automatically hide the |
21
|
|
|
* error container of the fields when they have no errors. |
22
|
|
|
*/ |
23
|
|
|
class FeedbackContainerDisplayCssAssetHandler extends AbstractAssetHandler |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Main function of this asset handler. |
28
|
|
|
* |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function getErrorContainerDisplayCss() |
32
|
|
|
{ |
33
|
|
|
$cssBlocks = []; |
34
|
|
|
$formConfiguration = $this->getFormObject()->getConfiguration(); |
35
|
|
|
|
36
|
|
|
foreach ($formConfiguration->getFields() as $fieldName => $field) { |
37
|
|
|
$formName = $this->getFormObject()->getName(); |
38
|
|
|
$errorSelector = DataAttributesAssetHandler::getFieldDataMessageKey($fieldName, 'error'); |
39
|
|
|
$warningSelector = DataAttributesAssetHandler::getFieldDataMessageKey($fieldName, 'warning'); |
40
|
|
|
$noticeSelector = DataAttributesAssetHandler::getFieldDataMessageKey($fieldName, 'notice'); |
41
|
|
|
$errorContainerCss = $field->getSettings()->getFeedbackContainerSelector(); |
42
|
|
|
|
43
|
|
|
$cssBlocks[] = <<<CSS |
44
|
|
|
form[name="$formName"]:not([$errorSelector="1"]):not([$warningSelector="1"]):not([$noticeSelector="1"]) $errorContainerCss { |
45
|
|
|
display: none!important; |
46
|
|
|
} |
47
|
|
|
CSS; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return implode(CRLF, $cssBlocks); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|