13
13
use Contao \DataContainer ;
14
14
use Contao \File ;
15
15
use Contao \System ;
16
+ use ContaoThemeManager \Core \Event \ExcludeHeadlineStyleEvent ;
17
+ use ContaoThemeManager \Core \Event \ExcludeSecondHeadlineEvent ;
16
18
use ContaoThemeManager \Core \StyleManager \StyleManagerXML ;
17
19
use Oveleon \ContaoThemeCompilerBundle \Compiler \FileCompiler ;
18
20
use Symfony \Component \Filesystem \Filesystem ;
@@ -43,29 +45,70 @@ public function extendHeadlineField($dc): void
43
45
'form ' ,
44
46
];
45
47
46
- $ objPalette = PaletteManipulator::create ()
47
- ->addField (['headlineStyle ' , 'headline2 ' , 'headline2Style ' ], 'headline ' );
48
+ $ eventDispatcher = System::getContainer ()->get ('event_dispatcher ' );
48
49
49
- $ test = $ GLOBALS ['TL_DCA ' ][$ dc ->table ]['palettes ' ];
50
+ $ excludeHeadlineStyleEvent = new ExcludeHeadlineStyleEvent ($ skipTypes );
51
+ $ excludeSecondHeadlineEvent = new ExcludeSecondHeadlineEvent ($ skipTypes );
52
+
53
+ $ eventDispatcher ->dispatch ($ excludeHeadlineStyleEvent );
54
+ $ eventDispatcher ->dispatch ($ excludeSecondHeadlineEvent );
55
+
56
+ $ excludeHeadlineStyleTypes = $ excludeHeadlineStyleEvent ->getTypes ();
57
+ $ excludeSecondHeadlineTypes = $ excludeSecondHeadlineEvent ->getTypes ();
50
58
51
59
foreach ($ GLOBALS ['TL_DCA ' ][$ dc ->table ]['palettes ' ] as $ name => $ palette )
52
60
{
53
- if (in_array ( $ name , $ skipTypes ))
61
+ if (is_array ( $ palette ))
54
62
{
55
63
continue ;
56
64
}
57
65
58
- if (!is_array ($ palette) && strpos ( $ palette , 'headlineStyle ' ) === false && strpos ($ palette , 'headline ' ) !== false )
66
+ if (!str_contains ($ palette , 'headline ' ) || str_contains ($ palette , 'headlineStyle ' ) )
59
67
{
60
- $ objPalette -> applyToPalette ( $ name , $ dc -> table ) ;
68
+ continue ;
61
69
}
70
+
71
+ $ includeHeadlineStyle = !in_array ($ name , $ excludeHeadlineStyleTypes , true );
72
+ $ includeSecondHeadline = !in_array ($ name , $ excludeSecondHeadlineTypes , true );
73
+
74
+ if (!$ includeHeadlineStyle && !$ includeSecondHeadline )
75
+ {
76
+ continue ;
77
+ }
78
+
79
+ $ fields = [];
80
+
81
+ if ($ includeHeadlineStyle )
82
+ {
83
+ $ fields [] = 'headlineStyle ' ;
84
+ }
85
+
86
+ if ($ includeSecondHeadline )
87
+ {
88
+ $ fields [] = 'headline2 ' ;
89
+
90
+ if ($ includeHeadlineStyle )
91
+ {
92
+ $ fields [] = 'headline2Style ' ;
93
+ }
94
+ }
95
+
96
+ if ([] === $ fields )
97
+ {
98
+ continue ;
99
+ }
100
+
101
+ PaletteManipulator::create ()
102
+ ->addField ($ fields , 'headline ' )
103
+ ->applyToPalette ($ name , $ dc ->table )
104
+ ;
62
105
}
63
106
}
64
107
65
108
/**
66
109
* Adjust the file palettes
67
110
*/
68
- public function adjustCustomFilePalettes (DataContainer $ dc )
111
+ public function adjustCustomFilePalettes (DataContainer $ dc ): void
69
112
{
70
113
if (!$ dc ->id )
71
114
{
@@ -109,7 +152,7 @@ public function onParseThemeManagerConfiguration($compiler, $configVars): void
109
152
}
110
153
}
111
154
112
- // Delete existing file if no custom config could be parsed
155
+ // Delete the existing file if no custom config could be parsed
113
156
if (0 === $ counter && file_exists ($ path = $ this ->rootDir . '/ ' . $ xmlPath ))
114
157
{
115
158
unlink ($ path );
@@ -124,7 +167,7 @@ public function onParseThemeManagerConfiguration($compiler, $configVars): void
124
167
}
125
168
126
169
/**
127
- * Creates a css file within assets
170
+ * Creates a CSS file within assets
128
171
*
129
172
* @throws \Exception
130
173
*/
0 commit comments