Skip to content

Commit

Permalink
Add BC layer for getAutoItem (fixes #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoglo committed Apr 11, 2024
1 parent 14e6657 commit 03930cd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
14 changes: 13 additions & 1 deletion contao/modules/ModuleRecommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Oveleon\ContaoRecommendationBundle;

use Contao\Config;
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\CoreBundle\Security\ContaoCorePermissions;
use Contao\Date;
use Contao\FilesModel;
Expand Down Expand Up @@ -252,7 +253,7 @@ protected function generateRecommendationUrl(RecommendationModel $objRecommendat
{
$objPage = PageModel::findByPk($objRecommendation->getRelated('pid')->jumpTo);

return StringUtil::ampersand($objPage->getFrontendUrl((Config::get('useAutoItem') ? '/' : '/items/') . ($objRecommendation->alias ?: $objRecommendation->id)));
return StringUtil::ampersand($objPage->getFrontendUrl(($this->useAutoItem() ? '/' : '/items/') . ($objRecommendation->alias ?: $objRecommendation->id)));
}

/**
Expand Down Expand Up @@ -343,4 +344,15 @@ protected function translateElapsedTime(int $value, string $strUnit = 'justNow')
{
return sprintf($GLOBALS['TL_LANG']['tl_recommendation'][$strUnit][!($value>1)], $value);
}

/**
* Checks weather auto_item should be used to provide BC
*
* @deprecated - To be removed when contao 4.13 support ends
* @internal
*/
protected function useAutoItem(): bool
{
return version_compare(ContaoCoreBundle::getVersion(), '5', '<') ? Config::get('useAutoItem') : true;
}
}
2 changes: 1 addition & 1 deletion contao/modules/ModuleRecommendationList.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function generate(): string
}

// Show the recommendation reader if an item has been selected
if ($this->recommendation_readerModule > 0 && (isset($_GET['items']) || (Config::get('useAutoItem') && isset($_GET['auto_item']))))
if ($this->recommendation_readerModule > 0 && (isset($_GET['items']) || ($this->useAutoItem() && isset($_GET['auto_item']))))
{
return $this->getFrontendModule($this->recommendation_readerModule, $this->strColumn);
}
Expand Down
17 changes: 13 additions & 4 deletions contao/modules/ModuleRecommendationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Contao\BackendTemplate;
use Contao\Config;
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\CoreBundle\Exception\InternalServerErrorException;
use Contao\CoreBundle\Exception\PageNotFoundException;
use Contao\Environment;
Expand All @@ -18,6 +19,7 @@
use Contao\System;
use Oveleon\ContaoRecommendationBundle\Model\RecommendationArchiveModel;
use Oveleon\ContaoRecommendationBundle\Model\RecommendationModel;
use Symfony\Component\HttpFoundation\Response;

/**
* Front end module "recommendation reader".
Expand Down Expand Up @@ -54,14 +56,21 @@ public function generate()
return $objTemplate->parse();
}

// Set the item from the auto_item parameter
if (!isset($_GET['items']) && isset($_GET['auto_item']) && Config::get('useAutoItem'))
{
$auto_item = Input::get('auto_item');

if (
version_compare(ContaoCoreBundle::getVersion(), '5', '<') &&
!isset($_GET['items']) &&
isset($_GET['auto_item']) &&
$this->useAutoItem()
) {
// Set the item from the auto_item parameter - Contao 4.13 BC
Input::setGet('items', Input::get('auto_item'));
$auto_item = Input::get('items');
}

// Return an empty string if "items" is not set (to combine list and reader on same page)
if (!Input::get('items'))
if (null === $auto_item)
{
return '';
}
Expand Down

0 comments on commit 03930cd

Please sign in to comment.