Skip to content

Commit 90e89b3

Browse files
committed
Added copy callback for pages
1 parent 8e0a9e4 commit 90e89b3

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

contao/dca/tl_page.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* Contao Open Source CMS
5+
* Copyright (c) 2005-2015 Leo Feyer
6+
*
7+
* @package semantic_html5
8+
* @copyright MEN AT WORK 2016
9+
* @author David Maack <david.maack@arcor.de>
10+
* @license LGPL-3.0+
11+
*/
12+
13+
/**
14+
* Callbacks
15+
*/
16+
$GLOBALS['TL_DCA']['tl_page']['config']['oncopy_callback'][] = array('SemanticHTML5\Backend\Callbacks', 'oncopyPageCallback');

src/Backend/Callbacks.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,47 @@ public static function ondeleteCallback(\DataContainer $dc, $id)
9191
}
9292
}
9393

94+
/**
95+
* This methods corrects the hml5-elements after using the copy function of
96+
* the tl_page table
97+
*
98+
* @param type $id
99+
* @param \DataContainer $dc
100+
*/
101+
public static function oncopyPageCallback($id, \DataContainer $dc)
102+
{
103+
104+
$pages = array($id);
105+
106+
//fetch the child pages, if needed
107+
if (\Input::get('childs')) {
108+
$pages = array_merge($pages, \Database::getInstance()->getChildRecords($id, 'tl_page'));
109+
110+
}
111+
112+
//fetch all html5 start elemnts and update them the end elements will be corrected automatically
113+
$elements = \Database::getInstance()
114+
->prepare(
115+
sprintf(
116+
'SELECT * FROM tl_content '
117+
. 'WHERE type = "sHtml5Start" '
118+
. 'AND pid IN '
119+
. '(SELECT id FROM tl_article WHERE pid in (%s))',
120+
implode(',', $pages))
121+
)->execute($pages);
122+
123+
//return if no elements were found
124+
if ($elements->numRows == 0) {
125+
return;
126+
}
127+
128+
$util = new TagUtils('tl_content');
129+
130+
while ($elements->next()) {
131+
$util->createOrUpdateCorresppondingTag($elements, true);
132+
}
133+
}
134+
94135
/**
95136
* This methods corrects the hml5-elements after using the copy function of
96137
* the tl_article table

0 commit comments

Comments
 (0)