12
12
13
13
namespace SemanticHTML5 \Backend ;
14
14
15
+ use Contao \BackendTemplate ;
16
+ use Contao \DataContainer ;
17
+ use Contao \System ;
18
+ use Contao \Database ;
19
+ use Contao \Input ;
20
+
15
21
/**
16
22
* Generall class to handle all backend callbacks
17
23
*/
@@ -31,7 +37,7 @@ class Callbacks
31
37
* Array tempData
32
38
*/
33
39
private static $ tempData = [];
34
-
40
+
35
41
/**
36
42
* Prevent direct instantiation (Singleton)
37
43
*/
@@ -55,18 +61,18 @@ public static function getInstance()
55
61
56
62
/**
57
63
* Adds or updates the corresponding star or end tag
58
- * @param \ DataContainer $dc
64
+ * @param DataContainer $dc
59
65
*/
60
- public static function onsubmitCallback (\ DataContainer $ dc )
61
- {
66
+ public static function onsubmitCallback (DataContainer $ dc )
67
+ {
62
68
//if this is not a html5 element, do nothing
63
69
if (in_array ($ dc ->activeRecord ->type , array ('sHtml5Start ' , 'sHtml5End ' ))) {
64
70
65
- $ item = $ dc ->activeRecord ;
66
71
$ util = new TagUtils ($ dc ->table );
72
+ $ item = $ util ->getCurrentRecord ($ dc ->activeRecord ->id );
67
73
68
74
//correct the sh5_pid if needed
69
- if ($ item ->type == 'sHtml5Start ' &&
75
+ if ($ item ->type == 'sHtml5Start ' &&
70
76
$ item ->id != $ item ->sh5_pid ) {
71
77
$ item = $ util ->updateTag ($ item ->id , array ('sh5_pid ' => $ item ->id ));
72
78
}
@@ -78,46 +84,47 @@ public static function onsubmitCallback(\DataContainer $dc)
78
84
79
85
/**
80
86
* Deletes the corresponding html5 tag
81
- *
82
- * @param \ DataContainer $dc
87
+ *
88
+ * @param DataContainer $dc
83
89
* @param int $id
84
90
*/
85
- public static function ondeleteCallback (\ DataContainer $ dc , $ id )
91
+ public static function ondeleteCallback (DataContainer $ dc , $ id )
86
92
{
87
93
//if this is not a html5 element, do nothing
88
94
if (in_array ($ dc ->activeRecord ->type , array ('sHtml5Start ' , 'sHtml5End ' ))) {
89
95
$ util = new TagUtils ($ dc ->table );
90
- $ util ->deleteCorrespondingTag ($ dc ->activeRecord );
96
+ $ item = $ util ->getCurrentRecord ($ dc ->activeRecord ->id );
97
+ $ util ->deleteCorrespondingTag ($ item );
91
98
}
92
99
}
93
100
94
101
/**
95
- * This methods corrects the hml5-elements after using the copy function of
102
+ * This methods corrects the hml5-elements after using the copy function of
96
103
* the tl_page table
97
- *
104
+ *
98
105
* @param type $id
99
- * @param \ DataContainer $dc
106
+ * @param DataContainer $dc
100
107
*/
101
- public static function oncopyPageCallback ($ id , \ DataContainer $ dc )
108
+ public static function oncopyPageCallback ($ id , DataContainer $ dc )
102
109
{
103
110
104
111
$ pages = array ($ id );
105
112
106
113
//fetch the child pages, if needed
107
- if (\ Input::get ('childs ' )) {
108
- $ pages = array_merge ($ pages , \ Database::getInstance ()->getChildRecords ($ id , 'tl_page ' ));
109
-
114
+ if (Input::get ('childs ' )) {
115
+ $ pages = array_merge ($ pages , Database::getInstance ()->getChildRecords ($ id , 'tl_page ' ));
116
+
110
117
}
111
118
112
119
//fetch all html5 start elemnts and update them the end elements will be corrected automatically
113
- $ elements = \ Database::getInstance ()
120
+ $ elements = Database::getInstance ()
114
121
->prepare (
115
122
sprintf (
116
123
'SELECT * FROM tl_content '
117
124
. 'WHERE type = "sHtml5Start" '
118
125
. 'AND pid IN '
119
126
. '(SELECT id FROM tl_article WHERE pid in (%s)) ' ,
120
- implode (', ' , $ pages ))
127
+ implode (', ' , array_fill ( 0 , count ( $ pages), ' ? ' ) ))
121
128
)->execute ($ pages );
122
129
123
130
//return if no elements were found
@@ -131,19 +138,19 @@ public static function oncopyPageCallback($id, \DataContainer $dc)
131
138
$ util ->createOrUpdateCorresppondingTag ($ elements , true );
132
139
}
133
140
}
134
-
141
+
135
142
/**
136
- * This methods corrects the hml5-elements after using the copy function of
143
+ * This methods corrects the hml5-elements after using the copy function of
137
144
* the tl_article table
138
- *
145
+ *
139
146
* @param type $id
140
- * @param \ DataContainer $dc
147
+ * @param DataContainer $dc
141
148
*/
142
- public static function oncopyArticleCallback ($ id , \ DataContainer $ dc )
149
+ public static function oncopyArticleCallback ($ id , DataContainer $ dc )
143
150
{
144
151
145
152
//fetch all html5 start elemnts and update them the end elements will be corrected automatically
146
- $ elements = \ Database::getInstance ()
153
+ $ elements = Database::getInstance ()
147
154
->prepare ('SELECT * FROM tl_content WHERE type = "sHtml5Start" AND pid = ? ' )
148
155
->execute ($ id );
149
156
@@ -160,18 +167,18 @@ public static function oncopyArticleCallback($id, \DataContainer $dc)
160
167
}
161
168
162
169
/**
163
- * This methods corrects the hml5-elements after using the copy function of
170
+ * This methods corrects the hml5-elements after using the copy function of
164
171
* the tl_content table
165
- *
172
+ *
166
173
* @param int $id The id of the new element
167
- * @param \ DataContainer $dc The datad container
174
+ * @param DataContainer $dc The datad container
168
175
*/
169
- public static function oncopyContentCallback ($ id , \ DataContainer $ dc )
176
+ public static function oncopyContentCallback ($ id , DataContainer $ dc )
170
177
{
171
-
172
- //only handle copyAll cases. If only a single element was copied the
178
+
179
+ //only handle copyAll cases. If only a single element was copied the
173
180
//onsubmit callback will handle the correction
174
- if (\ Input::get ('act ' ) == 'copyAll ' ) {
181
+ if (Input::get ('act ' ) == 'copyAll ' ) {
175
182
176
183
$ util = new TagUtils ($ dc ->table );
177
184
$ newElement = $ util ->getTag ($ id );
@@ -181,19 +188,19 @@ public static function oncopyContentCallback($id, \DataContainer $dc)
181
188
182
189
//save the old sh5_pid
183
190
$ oldPid = $ newElement ->sh5_pid ;
184
-
191
+
185
192
if ($ newElement ->type === 'sHtml5Start ' ) {
186
193
//update the sh5_pid
187
194
$ newElement = $ util ->updateTag ($ id , array ('sh5_pid ' => $ id ));
188
-
189
- //create an end tag, just in case it was not copied
195
+
196
+ //create an end tag, just in case it was not copied
190
197
$ correspondingId = $ util ->createOrUpdateCorresppondingTag ($ newElement );
191
-
198
+
192
199
//Save the new id if available
193
200
if ($ correspondingId !== null ) {
194
201
self ::$ tempData [$ oldPid ]['end ' ] = $ correspondingId ;
195
202
}
196
-
203
+
197
204
//also save the new start tag
198
205
self ::$ tempData [$ oldPid ]['start ' ] = $ newElement ->id ;
199
206
@@ -202,31 +209,32 @@ public static function oncopyContentCallback($id, \DataContainer $dc)
202
209
if (self ::$ tempData [$ oldPid ]['end ' ] !== null ) {
203
210
$ util ->deleteTag (self ::$ tempData [$ oldPid ]['end ' ]);
204
211
}
205
-
212
+
206
213
//get the new sh5_pid
207
214
$ newPid = (self ::$ tempData [$ oldPid ]['start ' ]) ? self ::$ tempData [$ oldPid ]['start ' ] : $ id ;
208
-
215
+
209
216
//update the new element and the corresponding tag
210
217
$ newElement = $ util ->updateTag ($ id , array ('sh5_pid ' => $ newPid ));
211
218
$ util ->createOrUpdateCorresppondingTag ($ newElement );
212
- }
219
+ }
213
220
}
214
221
}
215
222
}
216
223
217
224
/**
218
225
* Callback function to add the JS for colorization the the markup
219
- *
226
+ *
220
227
* @param type $objRow
221
228
* @param type $strBuffer
222
229
* @param type $objElement
223
230
* @return String
224
231
*/
225
232
public static function addColorizeJs ($ objRow , $ strBuffer , $ objElement )
226
233
{
227
- // if the element is no type of semantic html5 or the element ist not
234
+ // if the element is no type of semantic html5 or the element ist not
228
235
// renderen in the backend, do nothing
229
- if (TL_MODE == 'BE ' && ($ objRow ->type == 'sHtml5Start ' || $ objRow ->type == 'sHtml5End ' )) {
236
+ $ request = System::getContainer ()->get ('request_stack ' )->getCurrentRequest ();
237
+ if ($ request && System::getContainer ()->get ('contao.routing.scope_matcher ' )->isBackendRequest ($ request ) && ($ objRow ->type == 'sHtml5Start ' || $ objRow ->type == 'sHtml5End ' )) {
230
238
//get the color of the parent start-tag or rotate the color
231
239
if ($ objRow ->type == 'sHtml5End ' ) {
232
240
$ color = self ::$ elementColors [$ objRow ->sh5_pid ] ?? null ;
@@ -235,7 +243,7 @@ public static function addColorizeJs($objRow, $strBuffer, $objElement)
235
243
self ::$ elementColors [$ objRow ->id ] = $ color ;
236
244
}
237
245
238
- $ template = new \ BackendTemplate ('be_semantic_html5_colorizejs ' );
246
+ $ template = new BackendTemplate ('be_semantic_html5_colorizejs ' );
239
247
$ template ->id = $ objRow ->id ;
240
248
$ template ->color = $ color ;
241
249
@@ -247,11 +255,11 @@ public static function addColorizeJs($objRow, $strBuffer, $objElement)
247
255
248
256
/**
249
257
* Returns all valid html5 tag for the given datacontainer
250
- *
251
- * @param \ DataContainer $dc
258
+ *
259
+ * @param DataContainer $dc
252
260
* @return array The array with the valid html5 tags
253
261
*/
254
- public function getHtml5Tags (\ DataContainer $ dc ) {
262
+ public function getHtml5Tags (DataContainer $ dc ) {
255
263
256
264
return $ GLOBALS ['TL_HTML5 ' ]['tags ' ][$ dc ->table ];
257
265
}
0 commit comments