Skip to content

Commit

Permalink
Prepare 1.5.x (see #29)
Browse files Browse the repository at this point in the history
### Features 

- Added overviewPage and customLabel for recommendation readers 89420a7

- Added customLabel for recommendation lists 89420a7

- add an option to open a `dialog`-popup for recommendation lists 679b3f4 7820cd4 cc38f35
  > In case you don't need a reader and want to shorten your recommendations with line-clamp.
  > This does not include any CSS and uses the native HTML functionality
  
### Bugfixes

- Allow cspInlineStyles in recommendation teasers 7820cd4

- Do not show jumpTo link on reader pages when using reader on the same page e335f97

- Use own translations for `More` -description a70a94a

- Properly check auto-item aliases in contao 5 1804ecb

- Allow auto-item for Contao `5.x-dev` 31ff8db
  • Loading branch information
zoglo authored Apr 16, 2024
2 parents 756ee0e + 0377cb4 commit adf5150
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 27 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ The recommendation list can display published (and verified) recommendations fro
<td>Items per page</td>
<td>Number of recommendations per page - Activates pagination</td>
</tr>
<tr>
<td>Custom label</td>
<td>Allows customizing the translation to for the redirect link</td>
</tr>
<tr>
<td>Meta fields</td>
<td>Here you can select meta fields to display</td>
Expand All @@ -175,6 +179,10 @@ The recommendation list can display published (and verified) recommendations fro
<td>Module template</td>
<td>The modules template that is being used</td>
</tr>
<tr>
<td>Use dialog popup</td>
<td>Does not output the redirect link and embeds a dialog box instead. The `js_recommendation` template has to be included in the page layout</td>
</tr>
<tr>
<td>Image settings</td>
<td>You have the possibility to add pictures to your recommendations. These are the image settings for them</td>
Expand Down Expand Up @@ -203,6 +211,14 @@ The recommendation list can display published (and verified) recommendations fro
<td>Recommendation archives</td>
<td>Here you can select one or more archives to read recommendations from</td>
</tr>
<tr>
<td>Overview page</td>
<td>Adds the overview page to the template to not use ``javascript:history.go(-1)`` anymore</td>
</tr>
<tr>
<td>Custom label</td>
<td>Allows customizing the translation for the overview link</td>
</tr>
<tr>
<td>Meta fields</td>
<td>Here you can select meta fields to display</td>
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"contao/manager-plugin": "^2.3.1",
"contao/test-case": "^5.1",
"phpunit/phpunit": "^9.5",
"symfony/http-client": "^5.4 || ^6.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0"
"symfony/http-client": "^5.4 || ^6.0 || ^7.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0 || ^7.0"
},
"conflict": {
"contao/core": "*",
Expand All @@ -61,7 +61,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "1.4.x-dev"
"dev-main": "1.5.x-dev"
},
"contao-manager-plugin": "Oveleon\\ContaoRecommendationBundle\\ContaoManager\\Plugin"
},
Expand Down
20 changes: 10 additions & 10 deletions contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
$GLOBALS['TL_DCA']['tl_module']['palettes']['__selector__'][] = 'recommendation_activate';

// Add palettes to tl_module
$GLOBALS['TL_DCA']['tl_module']['palettes']['recommendationlist'] = '{title_legend},name,headline,type;{config_legend},recommendation_archives,recommendation_readerModule,recommendation_minRating,recommendation_featured,recommendation_order,numberOfItems,perPage;{template_legend:hide},recommendation_metaFields,recommendation_template,customTpl;{image_legend:hide},imgSize,recommendation_externalSize;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['recommendationreader'] = '{title_legend},name,headline,type;{config_legend},recommendation_archives;{template_legend:hide},recommendation_metaFields,recommendation_template,customTpl;{image_legend:hide},imgSize,recommendation_externalSize;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['recommendationlist'] = '{title_legend},name,headline,type;{config_legend},recommendation_archives,recommendation_readerModule,recommendation_minRating,recommendation_featured,recommendation_order,numberOfItems,perPage,customLabel;{template_legend:hide},recommendation_metaFields,recommendation_template,customTpl,recommendation_useDialog;{image_legend:hide},imgSize,recommendation_externalSize;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['recommendationreader'] = '{title_legend},name,headline,type;{config_legend},recommendation_archives,overviewPage,customLabel;{template_legend:hide},recommendation_metaFields,recommendation_template,customTpl;{image_legend:hide},imgSize,recommendation_externalSize;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['recommendationform'] = '{title_legend},name,headline,type;{config_legend},recommendation_archive,recommendation_optionalFormFields,recommendation_customFieldLabel,recommendation_notify,recommendation_moderate,recommendation_disableCaptcha;{privacy_legend},recommendation_privacyText;{redirect_legend:hide},jumpTo;{email_legend:hide},recommendation_activate;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';

$GLOBALS['TL_DCA']['tl_module']['subpalettes']['recommendation_activate'] = 'recommendation_activateJumpTo,recommendation_activateText';
Expand Down Expand Up @@ -72,6 +72,14 @@
'sql' => "varchar(255) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_module']['fields']['recommendation_useDialog'] = [
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
'eval' => ['submitOnChange'=>true, 'tl_class'=>'clr'],
'sql' => "char(1) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_module']['fields']['recommendation_order'] = [
'exclude' => true,
'inputType' => 'select',
Expand Down Expand Up @@ -178,14 +186,6 @@
'sql' => "varchar(64) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_module']['fields']['recommendation_template'] = [
'exclude' => true,
'inputType' => 'select',
'options_callback' => static fn () => Controller::getTemplateGroup('recommendation_'),
'eval' => ['includeBlankOption' => true, 'chosen' => true, 'tl_class'=>'w50'],
'sql' => "varchar(64) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_module']['fields']['recommendation_externalSize'] = [
'inputType' => 'text',
'eval' => ['multiple'=>true, 'size'=>2, 'rgxp'=>'natural', 'nospace'=>true, 'tl_class'=>'w50'],
Expand Down
4 changes: 4 additions & 0 deletions contao/languages/de/default.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<source>Currently there are no recommendations.</source>
<target>Zurzeit sind keine Bewertungen vorhanden.</target>
</trans-unit>
<trans-unit id="MSC.readRecommendation">
<source>Read the recommendation: %s</source>
<target>Die Bewertung lesen: %s</target>
</trans-unit>
</body>
</file>
</xliff>
12 changes: 12 additions & 0 deletions contao/languages/de/tl_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
<source>Here you can select the meta fields.</source>
<target>Hier können Sie die Meta-Felder auswählen.</target>
</trans-unit>
<trans-unit id="tl_module.recommendation_useDialog.0">
<source>Use dialog popup</source>
<target>Dialog-Popup nutzen</target>
</trans-unit>
<trans-unit id="tl_module.recommendation_useDialog.1">
<source>Adds a dialog popup for the recommendation and disables the forwarding page. You don't need a reader module for this feature.</source>
<target>Fügt ein Dialog-Popup für die Bewertung hinzu und deaktiviert die Weiterleitungsseite. Für diese Funktion benötigen Sie kein Lesemodul.</target>
</trans-unit>
<trans-unit id="tl_module.recommendation_optionalFormFields.0">
<source>Optional recommendation fields</source>
<target>Optionale Bewertungsfelder</target>
Expand Down Expand Up @@ -149,6 +157,10 @@
<source>Show only recommendations with a minimum rating.</source>
<target>Nur Bewertungen mit einem Mindestrating anzeigen.</target>
</trans-unit>
<trans-unit id="tl_module.includeRecTemplate">
<source>To use the dialog-popup, the &lt;em&gt;%s&lt;/em&gt; template needs to be included in the page layout.</source>
<target>Um das Dialog-Popup zu nutzen muss das &lt;em&gt;%s&lt;/em&gt;-Template im Seitenlayout eingebunden sein.</target>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 3 additions & 0 deletions contao/languages/en/default.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<trans-unit id="MSC.emptyRecommendationList">
<source>Currently there are no recommendations.</source>
</trans-unit>
<trans-unit id="MSC.readRecommendation">
<source>Read the recommendation: %s</source>
</trans-unit>
</body>
</file>
</xliff>
9 changes: 9 additions & 0 deletions contao/languages/en/tl_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
<trans-unit id="tl_module.recommendation_metaFields.1">
<source>Here you can select the meta fields.</source>
</trans-unit>
<trans-unit id="tl_module.recommendation_useDialog.0">
<source>Use dialog popup</source>
</trans-unit>
<trans-unit id="tl_module.recommendation_useDialog.1">
<source>Adds a dialog popup for the recommendation and disables the forwarding page. You don't need a reader module for this feature.</source>
</trans-unit>
<trans-unit id="tl_module.recommendation_optionalFormFields.0">
<source>Optional recommendation fields</source>
</trans-unit>
Expand Down Expand Up @@ -112,6 +118,9 @@
<trans-unit id="tl_module.recommendation_minRating.1">
<source>Show only recommendations with a minimum rating.</source>
</trans-unit>
<trans-unit id="tl_module.includeRecTemplate">
<source>To use the dialog-popup, the &lt;em&gt;%s&lt;/em&gt; template needs to be included in the page layout.</source>
</trans-unit>
</body>
</file>
</xliff>
24 changes: 19 additions & 5 deletions contao/modules/ModuleRecommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @property string $recommendation_template
* @property mixed $recommendation_metaFields
* @property mixed $recommendation_externalSize
* @property bool $recommendation_useDialog
*/
abstract class ModuleRecommendation extends Module
{
Expand Down Expand Up @@ -85,10 +86,18 @@ protected function parseRecommendation(RecommendationModel $objRecommendation, R
$objTemplate->class = $strClass;
$objTemplate->archiveId = $objRecommendationArchive->id;

if ($objRecommendationArchive->jumpTo)
$moreLabel = $this->customLabel ?: $GLOBALS['TL_LANG']['MSC']['more'];

if ($this->recommendation_useDialog)
{
$objTemplate->dialog = true;
$objTemplate->more = $moreLabel;
$objRecommendationArchive->jumpTo = null;
}
elseif ($objRecommendationArchive->jumpTo)
{
$objTemplate->allowRedirect = true;
$objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['more'], $objRecommendation, $objRecommendation->title, true);
$objTemplate->more = $this->generateLink($moreLabel, $objRecommendation, $objRecommendation->title ?: $objRecommendation->author, true);
}

if ($objRecommendation->title)
Expand Down Expand Up @@ -203,7 +212,12 @@ protected function parseRecommendations(Collection $objRecommendations): array
/** @var RecommendationArchiveModel $objRecommendationArchive */
$objRecommendationArchive = $recommendation->getRelated('pid');

$arrRecommendations[] = $this->parseRecommendation($recommendation, $objRecommendationArchive, ((++$count == 1) ? ' first' : '') . (($count == $limit) ? ' last' : '') . ((($count % 2) == 0) ? ' odd' : ' even'), $count);
$arrRecommendations[] = $this->parseRecommendation(
$recommendation,
$objRecommendationArchive,
((++$count == 1) ? ' first' : '') . (($count == $limit) ? ' last' : '') . ((($count % 2) == 0) ? ' odd' : ' even'),
$count
);
}

return $arrRecommendations;
Expand Down Expand Up @@ -253,7 +267,7 @@ protected function generateLink(string $strLink, RecommendationModel $objRecomme
{
return sprintf('<a href="%s" title="%s" itemprop="url">%s%s</a>',
$this->generateRecommendationUrl($objRecommendation),
StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $strTitle), true),
StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readRecommendation'], $strTitle), true),
$strLink,
($blnIsReadMore ? '<span class="invisible"> '.$strTitle.'</span>' : ''));
}
Expand Down Expand Up @@ -365,6 +379,6 @@ protected function translateElapsedTime(int $value, string $strUnit = 'justNow')
*/
protected function useAutoItem(): bool
{
return version_compare(ContaoCoreBundle::getVersion(), '5', '<') ? Config::get('useAutoItem') : true;
return !str_starts_with(ContaoCoreBundle::getVersion(), '5.') ? Config::get('useAutoItem') : true;
}
}
18 changes: 13 additions & 5 deletions contao/modules/ModuleRecommendationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
namespace Oveleon\ContaoRecommendationBundle;

use Contao\BackendTemplate;
use Contao\Config;
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\CoreBundle\Exception\InternalServerErrorException;
use Contao\CoreBundle\Exception\PageNotFoundException;
use Contao\Environment;
use Contao\Input;
use Contao\PageModel;
use Contao\StringUtil;
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 @@ -91,11 +90,20 @@ public function generate()
protected function compile()
{
$this->Template->recommendation = '';
$this->Template->referer = 'javascript:history.go(-1)';
$this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];

if ($this->overviewPage)
{
$this->Template->referer = PageModel::findById($this->overviewPage)->getFrontendUrl();
$this->Template->back = $this->customLabel ?: $GLOBALS['TL_LANG']['MSC']['goBack'];
}
else
{
$this->Template->referer = 'javascript:history.go(-1)';
$this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
}

// Get the recommendation item
$objRecommendation = RecommendationModel::findPublishedByParentAndIdOrAlias(Input::get('items'), $this->recommendation_archives);
$objRecommendation = RecommendationModel::findPublishedByParentAndIdOrAlias(Input::get('auto_item'), $this->recommendation_archives);

if (null === $objRecommendation)
{
Expand Down
14 changes: 14 additions & 0 deletions contao/templates/js/js_recommendation.html5
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php $GLOBALS['TL_HEAD'][] = '<script>
window.addEventListener("load", () => {
new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const elements = mutation.target.matches(".rec_show-modal") ? mutation.target : mutation.target.querySelectorAll(".rec_show-modal");
elements.forEach(element => {
element.addEventListener("click", (el) => {
document.querySelector(`.rec_dialog_${el.currentTarget.dataset?.id}`)?.showModal();
})
});
});
}).observe(document, { attributes: false, childList: true, subtree: true });
})
</script>';
16 changes: 14 additions & 2 deletions contao/templates/recommendation/recommendation_default.html5
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,27 @@
<?php endif; ?>

<div class="text" itemprop="description">
<?php if ($this->teaser && $this->allowRedirect): ?>
<?= $this->teaser ?>
<?php if ($this->teaser && ($this->allowRedirect || $this->dialog)): ?>
<?= method_exists($this, 'cspInlineStyles') ? $this->cspInlineStyles($this->teaser) : $this->teaser ?>
<?php else: ?>
<?= $this->text ?>
<?php endif; ?>
</div>

<?php if ($this->allowRedirect): ?>
<p class="more"><?= $this->more ?></p>
<?php elseif ($this->dialog): ?>
<p class="more">
<span class="rec_show-modal" data-id="<?= $this->id ?>"><?= $this->more ?></span>
</p>
<dialog class="rec_dialog rec_dialog_<?= $this->id ?>">
<div class="rec_dialog--content">
<?= $this->text ?>
<form class="dialog-btn" method="dialog">
<button><?= $this->trans('MSC.close') ?></button>
</form>
</div>
</dialog>
<?php endif; ?>
</div>

Expand Down
16 changes: 14 additions & 2 deletions contao/templates/recommendation/recommendation_latest.html5
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,27 @@
<?php endif; ?>

<div class="text" itemprop="description">
<?php if ($this->teaser && $this->allowRedirect): ?>
<?= $this->teaser ?>
<?php if ($this->teaser && ($this->allowRedirect || $this->dialog)): ?>
<?= method_exists($this, 'cspInlineStyles') ? $this->cspInlineStyles($this->teaser) : $this->teaser ?>
<?php else: ?>
<?= $this->text ?>
<?php endif; ?>
</div>

<?php if ($this->allowRedirect): ?>
<p class="more"><?= $this->more ?></p>
<?php elseif ($this->dialog): ?>
<p class="more">
<span class="rec_show-modal" data-id="<?= $this->id ?>"><?= $this->more ?></span>
</p>
<dialog class="rec_dialog rec_dialog_<?= $this->id ?>">
<div class="rec_dialog--content">
<?= $this->text ?>
<form class="dialog-btn" method="dialog">
<button><?= $this->trans('MSC.close') ?></button>
</form>
</div>
</dialog>
<?php endif; ?>
</div>

Expand Down
48 changes: 48 additions & 0 deletions src/EventListener/DataContainer/ModuleListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Oveleon\ContaoRecommendationBundle\EventListener\DataContainer;

use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
use Contao\CoreBundle\Security\ContaoCorePermissions;
use Contao\Database;
use Contao\DataContainer;
use Contao\Input;
use Contao\Message;
use Contao\ModuleModel;
use Contao\System;

class ModuleListener
{
#[AsCallback(table: 'tl_module', target: 'config.onload')]
public function showJsLibraryHint(DataContainer $dc): void
{
if ($_POST || Input::get('act') != 'edit')
{
return;
}

$security = System::getContainer()->get('security.helper');

if (
!$security->isGranted(ContaoCorePermissions::USER_CAN_ACCESS_MODULE, 'themes') ||
!$security->isGranted(ContaoCorePermissions::USER_CAN_ACCESS_LAYOUTS)
) {
return;
}

$objModule = ModuleModel::findByPk($dc->id);

if (null !== $objModule && 'recommendationlist' === $objModule->type)
{
// Get module
$objModule = Database::getInstance()->prepare("SELECT * FROM " . $dc->table . " WHERE id=?")
->limit(1)
->execute($dc->id);

if (null !== $objModule && !!$objModule->recommendation_useDialog)
{
Message::addInfo(sprintf(($GLOBALS['TL_LANG']['tl_module']['includeRecTemplate'] ?? null), 'js_recommendation'));
}
}
}
}
Loading

0 comments on commit adf5150

Please sign in to comment.