-
Notifications
You must be signed in to change notification settings - Fork 4
/
tl_content_extended.php
73 lines (59 loc) · 1.98 KB
/
tl_content_extended.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* @package EuF-Grid
* @author Sebastian Buck
* @license LGPL
* @copyright Erdmann & Freunde
*/
/**
* Label_Callback anpassen, um Grid-KLassen hinzuzufügen
*/
class tl_content_extended extends tl_content
{
public function addCteType($arrRow)
{
$return = parent::addCteType($arrRow);
$return = GridClass::addClassesToLabels($arrRow, $return);
return $return;
}
public function onsubmitCallback(\DataContainer $dc)
{
if (!in_array($dc->activeRecord->type, array('rowStart', 'colStart'))) {
return;
}
if ('auto' !== \Contao\Input::post('SUBMIT_TYPE') && $this->siblingStopElmentIsMissing(
$dc->activeRecord->pid,
$dc->activeRecord->ptable,
$dc->activeRecord->sorting,
substr($dc->activeRecord->type, 0, 3)
)) {
$data = $dc->activeRecord->row();
unset($data['id']);
$data['type'] = str_replace('Start', 'End', $dc->activeRecord->type);
$data['sorting'] += 1;
$newElement = new \Contao\ContentModel();
$newElement->setRow($data);
$newElement->save();
}
}
private function siblingStopElmentIsMissing($pid, $ptable, $sorting, $rowOrCol)
{
if (!in_array($rowOrCol, array('row', 'col'))) {
throw new InvalidArgumentException('Argument $rowOrCol must be either "row" or "col"');
}
$statement = \Contao\Database::getInstance()
->prepare(
'SELECT * FROM tl_content WHERE pid=? AND ptable=? AND sorting>? AND type IN("' . $rowOrCol . 'Start", "'
. $rowOrCol . 'End") ORDER BY sorting'
)
->limit(1)
->execute($pid, $ptable, $sorting);
if (false === $row = $statement->fetchAssoc()) {
return true;
}
if ($rowOrCol . 'End' !== $row['type']) {
return true;
}
return false;
}
}