Skip to content

Commit

Permalink
Changed callback calls to support Contao 4.13
Browse files Browse the repository at this point in the history
  • Loading branch information
hschottm committed Jun 1, 2022
1 parent 26e0897 commit 2c62649
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 243 deletions.
54 changes: 0 additions & 54 deletions classes/FileTableCallbackListener.php

This file was deleted.

24 changes: 14 additions & 10 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
* CSS files
*/

if (is_array($GLOBALS['TL_CSS']))
if (isset($GLOBALS['TL_CSS']) && \is_array($GLOBALS['TL_CSS']))
{
array_insert($GLOBALS['TL_CSS'], 1, 'system/modules/tags/assets/tag.css');
}
Expand All @@ -72,14 +72,14 @@
/**
* JavaScript files
*/
if (is_array($GLOBALS['TL_JAVASCRIPT']))
{
array_insert($GLOBALS['TL_JAVASCRIPT'], 1, 'system/modules/tags/assets/tag.js');
}
else
{
$GLOBALS['TL_JAVASCRIPT'] = array('system/modules/tags/assets/tag.js');
}
if (isset($GLOBALS['TL_JAVASCRIPT']) && \is_array($GLOBALS['TL_JAVASCRIPT']))
{
\array_insert($GLOBALS['TL_JAVASCRIPT'], 1, 'system/modules/tags/assets/tag.js');
}
else
{
$GLOBALS['TL_JAVASCRIPT'] = array('system/modules/tags/assets/tag.js');
}
}

/**
Expand All @@ -104,7 +104,11 @@
/**
* Add 'tag' to the URL keywords to prevent problems with URL manipulating modules like folderurl
*/
$GLOBALS['TL_CONFIG']['urlKeywords'] .= (strlen(trim($GLOBALS['TL_CONFIG']['urlKeywords'])) ? ',' : '') . 'tag';
if (isset($GLOBALS['TL_CONFIG']['urlKeywords'])) {
$GLOBALS['TL_CONFIG']['urlKeywords'] .= (strlen(trim($GLOBALS['TL_CONFIG']['urlKeywords'])) ? ',' : '') . 'tag';
} else {
$GLOBALS['TL_CONFIG']['urlKeywords'] = 'tag';
}
$GLOBALS['tags']['showInFeeds'] = true;

$GLOBALS['TL_FFL']['tag'] = 'TagFieldMemberFrontend';
Expand Down
43 changes: 17 additions & 26 deletions dca/tl_article.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* @license LGPL-3.0+
*/

class tl_article_tags extends tl_article
class tl_article_tags extends \Backend
{
public function removeArticle($dc)
public function removeArticle(\DataContainer $dc, $undoId)
{
$this->Database->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
->execute($dc->table, $dc->id);
Expand All @@ -23,7 +23,7 @@ public function removeArticle($dc)
}
}

public function removePage($dc)
public function removePage(\DataContainer $dc, $undoId)
{
// remove tags of all articles in the page
$arrArticles = $this->Database->prepare("SELECT DISTINCT id FROM tl_article WHERE pid = ?")
Expand All @@ -42,29 +42,16 @@ public function removePage($dc)
}
}

public function onCopy($dc)
{
if (is_array($this->Session->get('tl_article_copy')))
{
foreach ($this->Session->get('tl_article_copy') as $data)
{
$this->Database->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")
->execute($dc->id, $data['tag'], $data['table']);
}
}
$this->Session->set('tl_article_copy', null);
if (\Input::get('act') != 'copy')
{
return;
}
$objTags = $this->Database->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")
->execute(\Input::get('id'), $dc->table);
public function onCopy($insertID, \DataContainer $dc)
{
$objTags = $this->Database->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table);
$tags = array();
while ($objTags->next())
{
array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag));
while ($objTags->next()) {
\array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag));
}
foreach ($tags as $entry) {
$this->Database->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertID, $entry['tag'], $entry['table']);
}
$this->Session->set("tl_article_copy", $tags);
}
}

Expand All @@ -73,15 +60,19 @@ public function onCopy($dc)
* Change tl_article default palette
*/

$disabledObjects = deserialize($GLOBALS['TL_CONFIG']['disabledTagObjects'], true);
if (isset($GLOBALS['TL_CONFIG']['disabledTagObjects'])) {
$disabledObjects = deserialize($GLOBALS['TL_CONFIG']['disabledTagObjects'], true);
} else {
$disabledObjects = array();
}
if (!in_array('tl_article', $disabledObjects))
{
$GLOBALS['TL_DCA']['tl_article']['palettes']['default'] = str_replace("keywords", "keywords;{tags_legend},tags,tags_showtags", $GLOBALS['TL_DCA']['tl_article']['palettes']['default']);
$GLOBALS['TL_DCA']['tl_article']['palettes']['__selector__'][] = 'tags_showtags';
$GLOBALS['TL_DCA']['tl_article']['subpalettes']['tags_showtags'] = 'tags_max_tags,tags_relevance,tags_jumpto';
$GLOBALS['TL_DCA']['tl_article']['config']['ondelete_callback'][] = array('tl_article_tags', 'removeArticle');
$GLOBALS['TL_DCA']['tl_page']['config']['ondelete_callback'][] = array('tl_article_tags', 'removePage');
$GLOBALS['TL_DCA']['tl_article']['config']['onload_callback'][] = array('tl_article_tags', 'onCopy');
$GLOBALS['TL_DCA']['tl_article']['config']['oncopy_callback'][] = array('tl_article_tags', 'onCopy');
}

$GLOBALS['TL_DCA']['tl_article']['fields']['tags'] = array
Expand Down
41 changes: 16 additions & 25 deletions dca/tl_calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,39 @@
}
}

class tl_calendar_events_tags extends tl_calendar_events
class tl_calendar_events_tags extends \Backend
{
public function deleteEvents($dc)
public function deleteEvents(\DataContainer $dc, $undoId)
{
$this->Database->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
->execute($dc->table, $dc->id);
}

public function onCopy($dc)
{
if (is_array($this->Session->get('tl_calendar_events_copy')))
{
foreach ($this->Session->get('tl_calendar_events_copy') as $data)
{
$this->Database->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")
->execute($dc->id, $data['tag'], $data['table']);
}
}
$this->Session->set('tl_calendar_events_copy', null);
if (\Input::get('act') != 'copy')
{
return;
}
$objTags = $this->Database->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")
->execute(\Input::get('id'), $dc->table);
public function onCopy($insertID, \DataContainer $dc)
{
$objTags = $this->Database->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table);
$tags = array();
while ($objTags->next())
{
array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag));
while ($objTags->next()) {
\array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag));
}
foreach ($tags as $entry) {
$this->Database->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertID, $entry['tag'], $entry['table']);
}
$this->Session->set("tl_calendar_events_copy", $tags);
}
}

/**
* Change tl_news palettes
*/
$disabledObjects = deserialize($GLOBALS['TL_CONFIG']['disabledTagObjects'], true);
if (isset($GLOBALS['TL_CONFIG']['disabledTagObjects'])) {
$disabledObjects = deserialize($GLOBALS['TL_CONFIG']['disabledTagObjects'], true);
} else {
$disabledObjects = array();
}
if (!in_array('tl_calendar_events', $disabledObjects))
{
$GLOBALS['TL_DCA']['tl_calendar_events']['config']['ondelete_callback'][] = array('tl_calendar_events_tags', 'deleteEvents');
$GLOBALS['TL_DCA']['tl_calendar_events']['config']['onload_callback'][] = array('tl_calendar_events_tags', 'onCopy');
$GLOBALS['TL_DCA']['tl_calendar_events']['config']['oncopy_callback'][] = array('tl_calendar_events_tags', 'onCopy');
$GLOBALS['TL_DCA']['tl_calendar_events']['palettes']['default'] = str_replace("author", "author,tags", $GLOBALS['TL_DCA']['tl_calendar_events']['palettes']['default']);
}
$GLOBALS['TL_DCA']['tl_calendar_events']['fields']['tags'] = array
Expand Down
41 changes: 16 additions & 25 deletions dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
* @license LGPL-3.0+
*/

$disabledObjects = deserialize($GLOBALS['TL_CONFIG']['disabledTagObjects'], true);
if (isset($GLOBALS['TL_CONFIG']['disabledTagObjects'])) {
$disabledObjects = deserialize($GLOBALS['TL_CONFIG']['disabledTagObjects'], true);
} else {
$disabledObjects = array();
}
if (!in_array('tl_content', $disabledObjects))
{
foreach ($GLOBALS['TL_DCA']['tl_content']['palettes'] as $key => $palette)
Expand All @@ -25,7 +29,7 @@

$GLOBALS['TL_DCA']['tl_content']['palettes']['headline'] = str_replace('guests','guests,tagsonly', $GLOBALS['TL_DCA']['tl_content']['palettes']['headline']);
$GLOBALS['TL_DCA']['tl_content']['config']['ondelete_callback'][] = array('tl_content_tags', 'removeContentElement');
$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = array('tl_content_tags', 'onCopy');
$GLOBALS['TL_DCA']['tl_content']['config']['oncopy_callback'][] = array('tl_content_tags', 'onCopy');
$GLOBALS['TL_DCA']['tl_content']['palettes']['gallery'] = str_replace('numberOfItems','numberOfItems,tag_filter,tag_ignore;', $GLOBALS['TL_DCA']['tl_content']['palettes']['gallery']);
}

Expand Down Expand Up @@ -68,37 +72,24 @@
* @author Helmut Schottmüller <https://github.com/hschottm>
* @package Controller
*/
class tl_content_tags extends tl_content
class tl_content_tags extends \Backend
{
public function removeContentElement($dc)
public function removeContentElement(\DataContainer $dc, $undoId)
{
$this->Database->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
->execute($dc->table, $dc->id);
}

public function onCopy($dc)
{
if (is_array($this->Session->get('tl_content_copy')))
{
foreach ($this->Session->get('tl_content_copy') as $data)
{
$this->Database->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")
->execute($dc->id, $data['tag'], $data['table']);
}
}
$this->Session->set('tl_content_copy', null);
if (\Input::get('act') != 'copy')
{
return;
}
$objTags = $this->Database->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")
->execute(\Input::get('id'), $dc->table);
public function onCopy($insertID, \DataContainer $dc)
{
$objTags = $this->Database->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table);
$tags = array();
while ($objTags->next())
{
array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag));
while ($objTags->next()) {
\array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag));
}
foreach ($tags as $entry) {
$this->Database->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertID, $entry['tag'], $entry['table']);
}
$this->Session->set("tl_content_copy", $tags);
}
}

39 changes: 15 additions & 24 deletions dca/tl_faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
* Change tl_faq default palette
*/

$disabledObjects = deserialize($GLOBALS['TL_CONFIG']['disabledTagObjects'], true);
if (isset($GLOBALS['TL_CONFIG']['disabledTagObjects'])) {
$disabledObjects = deserialize($GLOBALS['TL_CONFIG']['disabledTagObjects'], true);
} else {
$disabledObjects = array();
}
if (!in_array('tl_article', $disabledObjects))
{
$GLOBALS['TL_DCA']['tl_faq']['palettes']['default'] = str_replace("author", "author,tags", $GLOBALS['TL_DCA']['tl_faq']['palettes']['default']);
$GLOBALS['TL_DCA']['tl_faq']['config']['ondelete_callback'][] = array('tl_faq_tags', 'removeFAQ');
$GLOBALS['TL_DCA']['tl_faq']['config']['onload_callback'][] = array('tl_faq_tags', 'onCopy');
$GLOBALS['TL_DCA']['tl_faq']['config']['oncopy_callback'][] = array('tl_faq_tags', 'onCopy');
}

$GLOBALS['TL_DCA']['tl_faq']['fields']['tags'] = array
Expand All @@ -29,37 +33,24 @@
'eval' => array('tl_class'=>'clr long')
);

class tl_faq_tags extends tl_faq
class tl_faq_tags extends \Backend
{
public function removeFAQ($dc)
public function removeFAQ(\DataContainer $dc, $undoId)
{
$this->Database->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
->execute($dc->table, $dc->id);
}

public function onCopy($dc)
public function onCopy($insertID, \DataContainer $dc)
{
if (is_array($this->Session->get('tl_faq_copy')))
{
foreach ($this->Session->get('tl_faq_copy') as $data)
{
$this->Database->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")
->execute($dc->id, $data['tag'], $data['table']);
}
}
$this->Session->set('tl_faq_copy', null);
if (\Input::get('act') != 'copy')
{
return;
}
$objTags = $this->Database->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")
->execute(\Input::get('id'), $dc->table);
$objTags = $this->Database->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->execute($dc->id, $dc->table);
$tags = array();
while ($objTags->next())
{
array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag));
while ($objTags->next()) {
\array_push($tags, array("table" => $dc->table, "tag" => $objTags->tag));
}
foreach ($tags as $entry) {
$this->Database->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->execute($insertID, $entry['tag'], $entry['table']);
}
$this->Session->set("tl_faq_copy", $tags);
}
}

Expand Down
Loading

0 comments on commit 2c62649

Please sign in to comment.