Skip to content

Commit b6fc566

Browse files
committed
added feature to exclude entries with certain tags from tag-clouds as well as listing-modules
1 parent 8752e01 commit b6fc566

File tree

15 files changed

+520
-120
lines changed

15 files changed

+520
-120
lines changed

depcheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Benny Born <benny.born@numero2.de>
77
* @author Michael Bösherz <michael.boesherz@numero2.de>
88
* @license LGPL-3.0-or-later
9-
* @copyright Copyright (c) 2021, numero2 - Agentur für digitales Marketing GbR
9+
* @copyright Copyright (c) 2024, numero2 - Agentur für digitales Marketing GbR
1010
*/
1111

1212

src/Controller/FrontendModule/AbstractTagCloudController.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Benny Born <benny.born@numero2.de>
77
* @author Michael Bösherz <michael.boesherz@numero2.de>
88
* @license LGPL-3.0-or-later
9-
* @copyright Copyright (c) 2025, numero2 - Agentur für digitales Marketing GbR
9+
* @copyright Copyright (c) 2026, numero2 - Agentur für digitales Marketing GbR
1010
*/
1111

1212

@@ -80,6 +80,11 @@ protected function getResponse( Template $template, ModuleModel $model, Request
8080

8181
foreach( $oTags as $oTag ) {
8282

83+
// do not add "invisible" tags to the template
84+
if( $oTag->invisible ) {
85+
continue;
86+
}
87+
8388
$aTag = TagUtil::parseTag($oTag);
8489
$alias = $aTag['tag'];
8590

@@ -101,16 +106,21 @@ protected function getResponse( Template $template, ModuleModel $model, Request
101106
}
102107
}
103108

104-
$href = TagUtil::generateUrlWithTags($oPageRedirect, $parameterTags, !empty($model->use_get_parameter));
109+
$count = $this->getTagCount($oTag, $model, $request);
110+
111+
if( $count > 0 ) {
105112

106-
$aTags[] = [
107-
'label' => $aTag['title']
108-
, 'active'=> $active
109-
, 'href' => $href
110-
, 'count' => $this->getTagCount($oTag, $model, $request)
111-
, 'class' => 'tag_' . StringUtil::standardize($aTag['tag']).($active?' active':'')
112-
, 'tag' => $aTag
113-
];
113+
$href = TagUtil::generateUrlWithTags($oPageRedirect, $parameterTags, !empty($model->use_get_parameter));
114+
115+
$aTags[] = [
116+
'label' => $aTag['title']
117+
, 'active'=> $active
118+
, 'href' => $href
119+
, 'count' => $count
120+
, 'class' => 'tag_' . StringUtil::standardize($aTag['tag']).($active?' active':'')
121+
, 'tag' => $aTag
122+
];
123+
}
114124
}
115125

116126
$template->tags = $aTags;

src/Controller/FrontendModule/EventsTagCloudController.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Benny Born <benny.born@numero2.de>
77
* @author Michael Bösherz <michael.boesherz@numero2.de>
88
* @license LGPL-3.0-or-later
9-
* @copyright Copyright (c) 2025, numero2 - Agentur für digitales Marketing GbR
9+
* @copyright Copyright (c) 2026, numero2 - Agentur für digitales Marketing GbR
1010
*/
1111

1212

@@ -66,14 +66,19 @@ protected function getTags( ModuleModel $model, Request $request ): ?Collection
6666

6767
$aTags = StringUtil::deserialize($model->event_tags, true);
6868

69+
$aExcludeTags = [];
70+
if( $model->tags_exclude ) {
71+
$aExcludeTags = StringUtil::deserialize($model->tags_exclude_list, true);
72+
}
73+
6974
if( !empty($aTags) ) {
7075

7176
$blnMatchAll = !empty($model->tags_match_all);
7277

73-
return TagsModel::findByTagsAndCalendar($aTags, $aCalendar, $blnMatchAll, $intStart, $intEnd, $blnFeatured);
78+
return TagsModel::findByTagsAndCalendar($aTags, $aCalendar, $blnMatchAll, $intStart, $intEnd, $blnFeatured, [], $aExcludeTags);
7479
}
7580

76-
return TagsModel::findByCalendar($aCalendar, $intStart, $intEnd, $blnFeatured);
81+
return TagsModel::findByCalendar($aCalendar, $intStart, $intEnd, $blnFeatured, [], $aExcludeTags);
7782
}
7883

7984

@@ -98,14 +103,19 @@ protected function getTagCount( TagsModel $tag, ModuleModel $model, Request $req
98103

99104
$aTags = StringUtil::deserialize($model->event_tags, true);
100105

106+
$aExcludeTags = [];
107+
if( $model->tags_exclude ) {
108+
$aExcludeTags = StringUtil::deserialize($model->tags_exclude_list, true);
109+
}
110+
101111
if( !empty($aTags) ) {
102112

103113
$blnMatchAll = !empty($model->tags_match_all);
104114

105-
return TagsModel::countByIdAndTagsAndCalendar($tag->id, $aTags, $aCalendar, $blnMatchAll, $intStart, $intEnd, $blnFeatured);
115+
return TagsModel::countByIdAndTagsAndCalendar($tag->id, $aTags, $aCalendar, $blnMatchAll, $intStart, $intEnd, $blnFeatured, [], $aExcludeTags);
106116
}
107117

108-
return TagsModel::countByIdAndCalendar($tag->id, $aCalendar);
118+
return TagsModel::countByIdAndCalendar($tag->id, $aCalendar, null, null, null, [], $aExcludeTags);
109119
}
110120

111121

src/Controller/FrontendModule/NewsTagCloudController.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Benny Born <benny.born@numero2.de>
77
* @author Michael Bösherz <michael.boesherz@numero2.de>
88
* @license LGPL-3.0-or-later
9-
* @copyright Copyright (c) 2025, numero2 - Agentur für digitales Marketing GbR
9+
* @copyright Copyright (c) 2026, numero2 - Agentur für digitales Marketing GbR
1010
*/
1111

1212

@@ -63,14 +63,19 @@ protected function getTags( ModuleModel $model, Request $request ): ?Collection
6363

6464
$aTags = StringUtil::deserialize($model->news_tags, true);
6565

66+
$aExcludeTags = [];
67+
if( $model->tags_exclude ) {
68+
$aExcludeTags = StringUtil::deserialize($model->tags_exclude_list, true);
69+
}
70+
6671
if( !empty($aTags) ) {
6772

6873
$blnMatchAll = !empty($model->tags_match_all);
6974

70-
return TagsModel::findByTagsAndNewsArchives($aTags, $aArchives, $blnMatchAll, $blnFeatured);
75+
return TagsModel::findByTagsAndNewsArchives($aTags, $aArchives, $blnMatchAll, $blnFeatured, [], $aExcludeTags);
7176
}
7277

73-
return TagsModel::findByNewsArchives($aArchives, $blnFeatured);
78+
return TagsModel::findByNewsArchives($aArchives, $blnFeatured, [], $aExcludeTags);
7479
}
7580

7681

@@ -93,14 +98,19 @@ protected function getTagCount( TagsModel $tag, ModuleModel $model, Request $req
9398

9499
$aTags = StringUtil::deserialize($model->news_tags, true);
95100

101+
$aExcludeTags = [];
102+
if( $model->tags_exclude ) {
103+
$aExcludeTags = StringUtil::deserialize($model->tags_exclude_list, true);
104+
}
105+
96106
if( !empty($aTags) ) {
97107

98108
$blnMatchAll = !empty($model->tags_match_all);
99109

100-
return TagsModel::countByIdAndTagsAndNewsArchives($tag->id, $aTags, $aArchives, $blnMatchAll, $blnFeatured);
110+
return TagsModel::countByIdAndTagsAndNewsArchives($tag->id, $aTags, $aArchives, $blnMatchAll, $blnFeatured, [], $aExcludeTags);
101111
}
102112

103-
return TagsModel::countByIdAndNewsArchives($tag->id, $aArchives, $blnFeatured);
113+
return TagsModel::countByIdAndNewsArchives($tag->id, $aArchives, $blnFeatured, [], $aExcludeTags);
104114
}
105115

106116

src/EventListener/DataContainer/ModuleListener.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Benny Born <benny.born@numero2.de>
77
* @author Michael Bösherz <michael.boesherz@numero2.de>
88
* @license LGPL-3.0-or-later
9-
* @copyright Copyright (c) 2024, numero2 - Agentur für digitales Marketing GbR
9+
* @copyright Copyright (c) 2026, numero2 - Agentur für digitales Marketing GbR
1010
*/
1111

1212

@@ -51,13 +51,17 @@ public function modifyPalettes( DataContainer $dc ): void {
5151
if( class_exists(ContaoCalendarBundle::class) ) {
5252

5353
PaletteManipulator::create()
54-
->addField(['ignoreTags', 'tags_match_all'], 'config_legend', 'append')
54+
->addField(['jumpToTags', 'ignoreTags', 'tags_match_all'], 'config_legend', PaletteManipulator::POSITION_APPEND)
5555
->applyToPalette('eventlist', $dc->table);
5656

57+
PaletteManipulator::create()
58+
->addField(['jumpToTags'], 'config_legend', PaletteManipulator::POSITION_APPEND)
59+
->applyToPalette('eventreader', $dc->table);
60+
5761
$pm = PaletteManipulator::create()
58-
->addField('jumpToTags', 'config_legend', 'append');
62+
->addField(['jumpToTags', 'ignoreTags', 'tags_match_all', 'tags_exclude'], 'config_legend', PaletteManipulator::POSITION_APPEND);
5963

60-
foreach( ['eventlist', 'eventreader', 'eventlist_related_tags', 'eventlist_tags'] as $palette ) {
64+
foreach( ['eventlist_related_tags', 'eventlist_tags'] as $palette ) {
6165
$pm->applyToPalette($palette, $dc->table);
6266
}
6367

@@ -66,22 +70,25 @@ public function modifyPalettes( DataContainer $dc ): void {
6670
->applyToPalette('eventlist_related_tags', $dc->table);
6771

6872
PaletteManipulator::create()
69-
->addField('event_tags', 'cal_calendar', 'after')
70-
->addField('tags_match_all', 'config_legend', 'append')
73+
->addField('event_tags', 'cal_calendar', PaletteManipulator::POSITION_AFTER)
7174
->applyToPalette('eventlist_tags', $dc->table);
7275

7376
}
7477

7578
if( class_exists(ContaoNewsBundle::class) ) {
7679

7780
PaletteManipulator::create()
78-
->addField(['ignoreTags', 'tags_match_all'], 'config_legend', 'append')
81+
->addField(['jumpToTags', 'ignoreTags', 'tags_match_all'], 'config_legend', PaletteManipulator::POSITION_APPEND)
7982
->applyToPalette('newslist', $dc->table);
8083

84+
PaletteManipulator::create()
85+
->addField(['jumpToTags'], 'config_legend', PaletteManipulator::POSITION_APPEND)
86+
->applyToPalette('newsreader', $dc->table);
87+
8188
$pm = PaletteManipulator::create()
82-
->addField('jumpToTags', 'config_legend', 'append');
89+
->addField(['jumpToTags', 'ignoreTags', 'tags_match_all', 'tags_exclude'], 'config_legend', PaletteManipulator::POSITION_APPEND);
8390

84-
foreach( ['newslist', 'newsreader', 'newslist_related_tags', 'newslist_tags'] as $palette ) {
91+
foreach( ['newslist_related_tags', 'newslist_tags'] as $palette ) {
8592
$pm->applyToPalette($palette, $dc->table);
8693
}
8794

@@ -90,8 +97,7 @@ public function modifyPalettes( DataContainer $dc ): void {
9097
->applyToPalette('newslist_related_tags', $dc->table);
9198

9299
PaletteManipulator::create()
93-
->addField('news_tags', 'news_archives', 'after')
94-
->addField('tags_match_all', 'config_legend', 'append')
100+
->addField('news_tags', 'news_archives', PaletteManipulator::POSITION_AFTER)
95101
->applyToPalette('newslist_tags', $dc->table);
96102
}
97103
}
@@ -108,30 +114,31 @@ public function modifyPalettes( DataContainer $dc ): void {
108114
*/
109115
public function changeFieldToNotMandatory( $value, DataContainer $dc ) {
110116

111-
if( in_array($dc->activeRecord->type, ['events_tag_cloud', 'news_tag_cloud']) ) {
117+
if( in_array($dc->activeRecord->type, ['events_tag_cloud', 'news_tag_cloud']) || $dc->activeRecord->tags_exclude ) {
112118
$GLOBALS['TL_DCA']['tl_module']['fields'][$dc->field]['eval']['mandatory'] = false;
113119
}
114120

115121
return $value;
116122
}
117123

118124
/**
119-
* Get all tags for news
125+
* Get all tags for for the current type of module
120126
*
121127
* @param Contao\DataContainer $dc
122128
*
123129
* @Callback(table="tl_module", target="fields.event_tags.options")
124130
* @Callback(table="tl_module", target="fields.news_tags.options")
131+
* @Callback(table="tl_module", target="fields.tags_exclude_list.options")
125132
*/
126133
public function getTags( DataContainer $dc ): array {
127134

128135
$tTag = TagsModel::getTable();
129136
$tRel = TagsRelModel::getTable();
130137

131138
$ptable = null;
132-
if( $dc->field === 'event_tags' ) {
139+
if( $dc->field === 'event_tags' || in_array($dc->activeRecord->type, ['events_tag_cloud', 'eventlist_related_tags', 'eventlist_tags']) ) {
133140
$ptable = CalendarEventsModel::getTable();
134-
} else if( $dc->field === 'news_tags' ) {
141+
} else if( $dc->field === 'news_tags' || in_array($dc->activeRecord->type, ['news_tag_cloud', 'newslist_related_tags', 'newslist_tags']) ) {
135142
$ptable = NewsModel::getTable();
136143
}
137144

src/EventListener/EventsListener.php

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Benny Born <benny.born@numero2.de>
77
* @author Michael Bösherz <michael.boesherz@numero2.de>
88
* @license LGPL-3.0-or-later
9-
* @copyright Copyright (c) 2025, numero2 - Agentur für digitales Marketing GbR
9+
* @copyright Copyright (c) 2026, numero2 - Agentur für digitales Marketing GbR
1010
*/
1111

1212

@@ -100,7 +100,6 @@ public function getAllEvents( array $events, array $calendars, int $timeStart, i
100100
}
101101
}
102102

103-
104103
// parse events
105104
foreach( $events as $day => $tstamps ) {
106105
foreach( $tstamps as $ts => $entries ) {
@@ -128,9 +127,17 @@ private function filterEventsByTags( array $events, array $tagsIds, Module $modu
128127

129128
$blnMultiple = !empty($module->tags_match_all);
130129

131-
if( !empty($tagsIds) ) {
130+
$aExcludeTags = [];
131+
if( $module->tags_exclude ) {
132+
$aExcludeTags = array_map('\intval', StringUtil::deserialize($module->tags_exclude_list, true));
133+
}
134+
135+
if( !empty($tagsIds) || $module->tags_exclude ) {
136+
132137
foreach( $events as $day => $tstamps ) {
138+
133139
foreach( $tstamps as $ts => $entries ) {
140+
134141
foreach( $entries as $i => $entry ) {
135142

136143
$e = &$events[$day][$ts][$i];
@@ -143,14 +150,26 @@ private function filterEventsByTags( array $events, array $tagsIds, Module $modu
143150
$eventTags = $eventTags->fetchEach('id');
144151
}
145152

146-
if( $blnMultiple ) {
147-
if( count(array_intersect($tagsIds, $eventTags)) === count($tagsIds) ) {
148-
continue;
153+
// check if event contains any of the excluded tags
154+
if( !empty($aExcludeTags) && count(array_intersect($eventTags, $aExcludeTags)) > 0 ) {
155+
unset($events[$day][$ts][$i]);
156+
continue;
157+
}
158+
159+
if( !empty($tagsIds) ) {
160+
161+
if( $blnMultiple ) {
162+
if( count(array_intersect($tagsIds, $eventTags)) === count($tagsIds) ) {
163+
continue;
164+
}
165+
} else {
166+
if( count(array_intersect($tagsIds, $eventTags)) ) {
167+
continue;
168+
}
149169
}
170+
150171
} else {
151-
if( count(array_intersect($tagsIds, $eventTags)) ) {
152-
continue;
153-
}
172+
continue;
154173
}
155174

156175
unset($events[$day][$ts][$i]);
@@ -205,6 +224,11 @@ public function parseEvent( array $event, Module $module ): array {
205224

206225
$tagsRaw[] = $aTag;
207226

227+
// do not add "invisible" tags to the template
228+
if( $tag->invisible ) {
229+
continue;
230+
}
231+
208232
if( $pageList ) {
209233

210234
$href = TagUtil::generateUrlWithTags($pageList, [$aTag['tag']]);

0 commit comments

Comments
 (0)