Skip to content

Commit

Permalink
Added copy callback for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmaack committed Sep 17, 2016
1 parent 8e0a9e4 commit 90e89b3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contao/dca/tl_page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* Contao Open Source CMS
* Copyright (c) 2005-2015 Leo Feyer
*
* @package semantic_html5
* @copyright MEN AT WORK 2016
* @author David Maack <[email protected]>
* @license LGPL-3.0+
*/

/**
* Callbacks
*/
$GLOBALS['TL_DCA']['tl_page']['config']['oncopy_callback'][] = array('SemanticHTML5\Backend\Callbacks', 'oncopyPageCallback');
41 changes: 41 additions & 0 deletions src/Backend/Callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 90e89b3

Please sign in to comment.