From beef713c2bc3d721c5594aa15853c8b0987f4286 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 24 Oct 2023 16:47:19 +0200 Subject: [PATCH 1/3] Add alias prefix for non-existing titles --- contao/dca/tl_recommendation_settings.php | 17 ++++++++++++++++- contao/languages/de/tl_recommendation.xlf | 4 ++++ .../de/tl_recommendation_settings.xlf | 18 +++++++++++++++--- contao/languages/en/tl_recommendation.xlf | 3 +++ .../en/tl_recommendation_settings.xlf | 13 +++++++++++-- .../DataContainer/RecommendationListener.php | 8 +++++++- 6 files changed, 56 insertions(+), 7 deletions(-) diff --git a/contao/dca/tl_recommendation_settings.php b/contao/dca/tl_recommendation_settings.php index ebb78ff..dd7c59c 100644 --- a/contao/dca/tl_recommendation_settings.php +++ b/contao/dca/tl_recommendation_settings.php @@ -20,7 +20,7 @@ // Palettes 'palettes' => [ - 'default' => '{recommendation_legend},recommendationDefaultImage,recommendationActiveColor;' + 'default' => '{recommendation_legend},recommendationDefaultImage,recommendationActiveColor,recommendationAliasPrefix;' ], // Fields @@ -44,6 +44,21 @@ static function ($value) return serialize(array_map('\Contao\StringUtil::restoreBasicEntities', $value)); } ] + ], + 'recommendationAliasPrefix' => [ + 'inputType' => 'text', + 'eval' => ['rgxp'=>'alias', 'maxlength'=>255, 'tl_class'=>'w50 clr'], + 'save_callback' => [ + static function ($value) + { + if (!$value) + { + $value = &$GLOBALS['TL_LANG']['tl_recommendation_settings']['defaultPrefix']; + } + + return $value; + } + ] ] ] ]; diff --git a/contao/languages/de/tl_recommendation.xlf b/contao/languages/de/tl_recommendation.xlf index f5b4311..ae10a48 100644 --- a/contao/languages/de/tl_recommendation.xlf +++ b/contao/languages/de/tl_recommendation.xlf @@ -317,6 +317,10 @@ just now gerade eben + + recommendation + bewertung + diff --git a/contao/languages/de/tl_recommendation_settings.xlf b/contao/languages/de/tl_recommendation_settings.xlf index cd147f0..7f13336 100644 --- a/contao/languages/de/tl_recommendation_settings.xlf +++ b/contao/languages/de/tl_recommendation_settings.xlf @@ -1,6 +1,10 @@ + + Settings + Einstellungen + Default image Standard-Bild @@ -17,9 +21,17 @@ Color value will be set as inline css style in the html code. Farbwert wird als inline css style im HTML code gesetzt. - - Settings - Einstellungen + + Alias prefix + Alias-Präfix + + + Here you can enter an alias prefix that will precede a recommendation alias if no title has been entered. + Hier können Sie einen Alias-Präfix eingeben, der einem Bewertungsalias vorangestellt wird, wenn kein Titel eingegeben wurde. + + + recommendation + bewertung diff --git a/contao/languages/en/tl_recommendation.xlf b/contao/languages/en/tl_recommendation.xlf index 1073f30..2849d0b 100644 --- a/contao/languages/en/tl_recommendation.xlf +++ b/contao/languages/en/tl_recommendation.xlf @@ -238,6 +238,9 @@ just now + + recommendation + diff --git a/contao/languages/en/tl_recommendation_settings.xlf b/contao/languages/en/tl_recommendation_settings.xlf index 15c2e9a..415a7e4 100644 --- a/contao/languages/en/tl_recommendation_settings.xlf +++ b/contao/languages/en/tl_recommendation_settings.xlf @@ -1,6 +1,9 @@ + + Settings + Default image @@ -13,8 +16,14 @@ Color value will be set as inline css style in the html code. - - Settings + + Alias prefix + + + Here you can enter an alias prefix that will precede a recommendation alias if no title has been entered. + + + recommendation diff --git a/src/EventListener/DataContainer/RecommendationListener.php b/src/EventListener/DataContainer/RecommendationListener.php index 7204df9..3bd3609 100644 --- a/src/EventListener/DataContainer/RecommendationListener.php +++ b/src/EventListener/DataContainer/RecommendationListener.php @@ -82,7 +82,13 @@ public function generateRecommendationAlias($varValue, DataContainer $dc) // Generate alias if there is none if (!$varValue) { - $varValue = System::getContainer()->get('contao.slug')->generate($dc->activeRecord->title, RecommendationArchiveModel::findByPk($dc->activeRecord->pid)->jumpTo, $aliasExists); + // Use alias prefix if no title has been set + if (!$title = $dc->activeRecord->title) + { + $title = Config::get('recommendationAliasPrefix') ?? 'recommendation'; + } + + $varValue = System::getContainer()->get('contao.slug')->generate($title, RecommendationArchiveModel::findByPk($dc->activeRecord->pid)->jumpTo, $aliasExists); } elseif (preg_match('/^[1-9]\d*$/', $varValue)) { From 5eefcc288db0b54f323b3483caab54b0ed9501f6 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek <55794780+zoglo@users.noreply.github.com> Date: Tue, 24 Oct 2023 22:15:24 +0200 Subject: [PATCH 2/3] Consider numeric aliases --- src/Model/RecommendationModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/RecommendationModel.php b/src/Model/RecommendationModel.php index e4dd912..903f406 100644 --- a/src/Model/RecommendationModel.php +++ b/src/Model/RecommendationModel.php @@ -124,7 +124,7 @@ public static function findPublishedByParentAndIdOrAlias(mixed $varId, $arrPids, } $t = static::$strTable; - $arrColumns = !is_numeric($varId) ? ["$t.alias=?"] : ["$t.id=?"]; + $arrColumns = !preg_match('/^[1-9]\d*$/', $varId) ? ["BINARY $t.alias=?"] : ["$t.id=?"]; $arrColumns[] = "$t.pid IN(" . implode(',', array_map('\intval', $arrPids)) . ") AND $t.verified='1'"; if (!static::isPreviewMode($arrOptions)) From 2b807eaf6e6e2d9e013f142372e9148022e89f3e Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek <55794780+zoglo@users.noreply.github.com> Date: Tue, 24 Oct 2023 22:26:57 +0200 Subject: [PATCH 3/3] Update readme --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a7437c..099eee1 100644 --- a/README.md +++ b/README.md @@ -103,8 +103,12 @@ If you are familiar using the news- or events bundle, you should be able to set ![Admin View: Recommendation Archive Settings](https://www.oveleon.de/share/github-assets/contao-recommendation-bundle/recommendationArchiveSettings.jpg) +5. Setting up the recommendation alias + - Within the recommendation settings, you can update the default-prefix for aliases when no title has been given -5. Setting up a recommendation-reader for a redirect page + ![Admin View: Recommendation Reader](https://www.oveleon.de/share/github-assets/contao-recommendation-bundle/defaultAlias.jpg) + +6. Setting up a recommendation-reader for a redirect page 1. Create the front end module *recommendation-reader* 2. Choose your recommendation archive/s 3. Choose the meta fields you want to show in your front end