From b66d7fdf7bdf05669108a28388b7505d0efa433a Mon Sep 17 00:00:00 2001 From: fritzmg Date: Sun, 31 Jul 2022 10:35:19 +0100 Subject: [PATCH] unlock Contao 5 --- composer.json | 2 +- src/Models/NewsRelatedModel.php | 21 ++++++++++++++------- src/Resources/contao/dca/tl_news.php | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 890d9b7..61c78e1 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ ], "require":{ "php": ">=7.1", - "contao/core-bundle": "^4.9" + "contao/core-bundle": "^4.9 || ^5.0" }, "require-dev": { "contao/manager-plugin": "^2.0" diff --git a/src/Models/NewsRelatedModel.php b/src/Models/NewsRelatedModel.php index 20f2674..8268985 100644 --- a/src/Models/NewsRelatedModel.php +++ b/src/Models/NewsRelatedModel.php @@ -10,6 +10,13 @@ namespace ContaoNewsRelatedBundle\Models; +use Contao\Config; +use Contao\Date; +use Contao\Input; +use Contao\NewsModel; +use Contao\StringUtil; +use Contao\System; + /* * Dynamic parent class */ @@ -55,13 +62,13 @@ public function newsListFetchItems($newsArchives, $blnFeatured, $limit, $offset, $retNoItem = $objModule->disableEmpty ? false : null; // get the table and prepare columns, values and options - $t = \NewsModel::getTable(); + $t = self::getTable(); $arrColumns = ["$t.pid IN(".implode(',', array_map('intval', $newsArchives)).')']; $arrValues = []; $arrOptions = []; // get the active item - $item = \Config::get('useAutoItem') ? \Input::get('auto_item') : !\Input::get('items'); + $item = Config::get('useAutoItem') ? Input::get('auto_item') : !Input::get('items'); // check if there is an active tem if (!$item) { @@ -69,7 +76,7 @@ public function newsListFetchItems($newsArchives, $blnFeatured, $limit, $offset, } // get the news - $objNews = \NewsModel::findByAlias($item); + $objNews = self::findByAlias($item); // check if news was found if (!$objNews) { @@ -77,7 +84,7 @@ public function newsListFetchItems($newsArchives, $blnFeatured, $limit, $offset, } // Get the related news - $arrRelated = deserialize($objNews->relatedNews); + $arrRelated = StringUtil::deserialize($objNews->relatedNews); // Check if any related news are defined if (!$arrRelated) { @@ -99,8 +106,8 @@ public function newsListFetchItems($newsArchives, $blnFeatured, $limit, $offset, $arrColumns[] = "$t.featured=''"; } - if (!BE_USER_LOGGED_IN || TL_MODE === 'BE') { - $time = \Date::floorToMinute(); + if (!System::getContainer()->get('contao.security.token_checker')->isPreviewMode()) { + $time = Date::floorToMinute(); $arrColumns[] = "($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'".($time + 60)."') AND $t.published='1'"; } @@ -147,7 +154,7 @@ public function newsListFetchItems($newsArchives, $blnFeatured, $limit, $offset, // support for news_categories if (class_exists('\NewsCategories\NewsModel')) { $GLOBALS['NEWS_FILTER_CATEGORIES'] = $objModule->news_filterCategories ? true : false; - $GLOBALS['NEWS_FILTER_DEFAULT'] = deserialize($objModule->news_filterDefault, true); + $GLOBALS['NEWS_FILTER_DEFAULT'] = StringUtil::deserialize($objModule->news_filterDefault, true); $GLOBALS['NEWS_FILTER_PRESERVE'] = $objModule->news_filterPreserve; $arrColumns = self::filterByCategories($arrColumns); diff --git a/src/Resources/contao/dca/tl_news.php b/src/Resources/contao/dca/tl_news.php index dc54bac..29693ff 100644 --- a/src/Resources/contao/dca/tl_news.php +++ b/src/Resources/contao/dca/tl_news.php @@ -19,7 +19,7 @@ ]; $pm = PaletteManipulator::create() - ->addLegend('related_news_legend', null, PaletteManipulator::POSITION_AFTER, true) + ->addLegend('related_news_legend', 'foobar', PaletteManipulator::POSITION_AFTER, true) ->addField('relatedNews', 'related_news_legend', PaletteManipulator::POSITION_APPEND) ;