From 90e89b3a87a91a89c2911fd261ca8959c0f4bdeb Mon Sep 17 00:00:00 2001 From: David Maack Date: Sat, 17 Sep 2016 17:40:49 +0200 Subject: [PATCH] Added copy callback for pages --- contao/dca/tl_page.php | 16 +++++++++++++++ src/Backend/Callbacks.php | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 contao/dca/tl_page.php diff --git a/contao/dca/tl_page.php b/contao/dca/tl_page.php new file mode 100644 index 0000000..be663ec --- /dev/null +++ b/contao/dca/tl_page.php @@ -0,0 +1,16 @@ + + * @license LGPL-3.0+ + */ + +/** + * Callbacks + */ +$GLOBALS['TL_DCA']['tl_page']['config']['oncopy_callback'][] = array('SemanticHTML5\Backend\Callbacks', 'oncopyPageCallback'); \ No newline at end of file diff --git a/src/Backend/Callbacks.php b/src/Backend/Callbacks.php index 6a24408..8a550a6 100644 --- a/src/Backend/Callbacks.php +++ b/src/Backend/Callbacks.php @@ -91,6 +91,47 @@ public static function ondeleteCallback(\DataContainer $dc, $id) } } +/** + * This methods corrects the hml5-elements after using the copy function of + * the tl_page table + * + * @param type $id + * @param \DataContainer $dc + */ + public static function oncopyPageCallback($id, \DataContainer $dc) + { + + $pages = array($id); + + //fetch the child pages, if needed + if (\Input::get('childs')) { + $pages = array_merge($pages, \Database::getInstance()->getChildRecords($id, 'tl_page')); + + } + + //fetch all html5 start elemnts and update them the end elements will be corrected automatically + $elements = \Database::getInstance() + ->prepare( + sprintf( + 'SELECT * FROM tl_content ' + . 'WHERE type = "sHtml5Start" ' + . 'AND pid IN ' + . '(SELECT id FROM tl_article WHERE pid in (%s))', + implode(',', $pages)) + )->execute($pages); + + //return if no elements were found + if ($elements->numRows == 0) { + return; + } + + $util = new TagUtils('tl_content'); + + while ($elements->next()) { + $util->createOrUpdateCorresppondingTag($elements, true); + } + } + /** * This methods corrects the hml5-elements after using the copy function of * the tl_article table