Skip to content

Commit 707ab9f

Browse files
authored
Merge pull request #44 from menatwork/contao-5.3-fix
Contao 5.3 fix
2 parents 292ea67 + 0fa7dd9 commit 707ab9f

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

src/Backend/Callbacks.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Contao\BackendTemplate;
1616
use Contao\DataContainer;
1717
use Contao\System;
18+
use Contao\Database;
19+
use Contao\Input;
1820

1921
/**
2022
* Generall class to handle all backend callbacks
@@ -66,8 +68,8 @@ public static function onsubmitCallback(DataContainer $dc)
6668
//if this is not a html5 element, do nothing
6769
if (in_array($dc->activeRecord->type, array('sHtml5Start', 'sHtml5End'))) {
6870

69-
$item = $dc->activeRecord;
7071
$util = new TagUtils($dc->table);
72+
$item = $util->getCurrentRecord($dc->activeRecord->id);
7173

7274
//correct the sh5_pid if needed
7375
if ($item->type == 'sHtml5Start' &&
@@ -91,7 +93,8 @@ public static function ondeleteCallback(DataContainer $dc, $id)
9193
//if this is not a html5 element, do nothing
9294
if (in_array($dc->activeRecord->type, array('sHtml5Start', 'sHtml5End'))) {
9395
$util = new TagUtils($dc->table);
94-
$util->deleteCorrespondingTag($dc->activeRecord);
96+
$item = $util->getCurrentRecord($dc->activeRecord->id);
97+
$util->deleteCorrespondingTag($item);
9598
}
9699
}
97100

@@ -108,13 +111,13 @@ public static function oncopyPageCallback($id, DataContainer $dc)
108111
$pages = array($id);
109112

110113
//fetch the child pages, if needed
111-
if (\Input::get('childs')) {
112-
$pages = array_merge($pages, \Database::getInstance()->getChildRecords($id, 'tl_page'));
114+
if (Input::get('childs')) {
115+
$pages = array_merge($pages, Database::getInstance()->getChildRecords($id, 'tl_page'));
113116

114117
}
115118

116119
//fetch all html5 start elemnts and update them the end elements will be corrected automatically
117-
$elements = \Database::getInstance()
120+
$elements = Database::getInstance()
118121
->prepare(
119122
sprintf(
120123
'SELECT * FROM tl_content '
@@ -147,7 +150,7 @@ public static function oncopyArticleCallback($id, DataContainer $dc)
147150
{
148151

149152
//fetch all html5 start elemnts and update them the end elements will be corrected automatically
150-
$elements = \Database::getInstance()
153+
$elements = Database::getInstance()
151154
->prepare('SELECT * FROM tl_content WHERE type = "sHtml5Start" AND pid = ?')
152155
->execute($id);
153156

@@ -175,7 +178,7 @@ public static function oncopyContentCallback($id, DataContainer $dc)
175178

176179
//only handle copyAll cases. If only a single element was copied the
177180
//onsubmit callback will handle the correction
178-
if (\Input::get('act') == 'copyAll') {
181+
if (Input::get('act') == 'copyAll') {
179182

180183
$util = new TagUtils($dc->table);
181184
$newElement = $util->getTag($id);

src/Backend/TagUtils.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
namespace SemanticHTML5\Backend;
1414

1515
use Contao\Database\Result;
16+
use Contao\Database;
1617

1718
/**
18-
* Generall Helper Class for handling start and end tags
19+
* General Helper Class for handling start and end tags
1920
*/
2021
class TagUtils
2122
{
@@ -126,7 +127,7 @@ public function deleteCorrespondingTag(Result $item)
126127
*/
127128
public function getTag($id) {
128129

129-
$item = \Database::getInstance()
130+
$item = Database::getInstance()
130131
->prepare('SELECT * FROM ' . $this->table . ' WHERE (type ="sHtml5Start" OR type = "sHtml5End") AND id = ?')
131132
->execute($id);
132133

@@ -141,7 +142,7 @@ public function getTag($id) {
141142
public function getcorrespondingTag(Result $item)
142143
{
143144
$type = $this->matchingTags[$item->type];
144-
$result = \Database::getInstance()
145+
$result = Database::getInstance()
145146
->prepare('SELECT * FROM ' . $this->table . ' WHERE pid = ? AND sh5_pid = ? AND type = ?')
146147
->execute($item->pid, $item->sh5_pid, $type);
147148

@@ -168,11 +169,11 @@ public function createTag($data)
168169
unset($data['id']);
169170

170171
//remove fields which are not present in the db table (See #22)
171-
$tableFields = array_flip(\Database::getInstance()->getFieldNames($this->table));
172+
$tableFields = array_flip(Database::getInstance()->getFieldNames($this->table));
172173
$data = array_intersect_key($data, $tableFields);
173174

174175
// Insert the tag
175-
$result = \Database::getInstance()
176+
$result = Database::getInstance()
176177
->prepare("INSERT INTO " . $this->table . " %s")
177178
->set($data)
178179
->execute();
@@ -194,7 +195,7 @@ public function createTag($data)
194195
public function deleteTag($id)
195196
{
196197
//ToDo: add the UnDo functionality from contao
197-
\Database::getInstance()
198+
Database::getInstance()
198199
->prepare('DELETE FROM ' . $this->table . ' WHERE id = ? '
199200
. 'AND (type = "sHtml5Start" OR type = "sHtml5End")')
200201
->execute($id);
@@ -210,17 +211,28 @@ public function deleteTag($id)
210211
public function updateTag($id, $data)
211212
{
212213
//update the database
213-
\Database::getInstance()
214+
Database::getInstance()
214215
->prepare('UPDATE ' . $this->table . ' %s WHERE id = ?')
215216
->set($data)
216217
->execute($id);
217218

218219
//return the updated element
219-
return \Database::getInstance()
220-
->prepare('SELECT * FROM ' . $this->table . ' WHERE id = ?')
221-
->execute($id);
220+
return $this->getCurrentRecord($id);
222221
}
223222

223+
/**
224+
* Returns the current record with the given id as Result
225+
*
226+
* @param int $id The id of the element
227+
* @return Result The current element as a mysql result
228+
*/
229+
public function getCurrentRecord($id): Result {
230+
return Database::getInstance()
231+
->prepare('SELECT * FROM ' . $this->table . ' WHERE id = ?')
232+
->execute($id);
233+
}
234+
235+
224236
/**
225237
* Collects all fields which should have the same values foro start and end
226238
* tag, e.g. the show to guest only flag. See #30

0 commit comments

Comments
 (0)