Skip to content

Commit b1f136a

Browse files
committed
Add URI to TaggerGetCurrentTag snippet
1 parent 4f09217 commit b1f136a

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

Diff for: core/components/tagger/docs/changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Changelog for Tagger.
22

3+
- Add URI to TaggerGetCurrentTag snippet
34
- Add linkOneTagPerGroup option to TaggerGetTags
45
- Add option to include current tags in TaggerGetTags url
56
- Add Tag Label for frontend usage

Diff for: core/components/tagger/elements/snippets/taggergetcurrenttag.snippet.php

+50-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
*
77
*
88
* PROPERTIES:
9-
*
10-
* &tagTpl string optional Name of a chunk that will be used for each Tag. If no chunk is given, array with available placeholders will be rendered
11-
* &groupTpl string optional Name of a chunk that will be used for each Tag. If no chunk is given, array with available placeholders will be rendered
12-
* &tagSeparator string optional String separator, that will be used for separating Tags
13-
* &groupSeparator string optional String separator, that will be used for separating Groups
9+
*
10+
* &tagTpl string optional Name of a chunk that will be used for each Tag. If no chunk is given, array with available placeholders will be rendered
11+
* &groupTpl string optional Name of a chunk that will be used for each Group. If no chunk is given, array with available placeholders will be rendered
12+
* &outTpl string optional Name of a chunk that will be used for wrapping all groups. If no chunk is given, tags will be rendered without a wrapper
13+
* &tagSeparator string optional String separator, that will be used for separating Tags
14+
* &groupSeparator string optional String separator, that will be used for separating Groups
15+
* &target int optional An ID of a resource that will be used for generating URI for a Tag. If no ID is given, current Resource ID will be used
16+
* &friendlyURL int optional If set, will be used instead of friendly_urls system setting to generate URL
17+
* &linkTagScheme int|string optional Strategy to generate URLs, available values: -1, 0, 1, full, abs, http, https; Default: link_tag_scheme system setting
1418
*
1519
* USAGE:
1620
*
@@ -25,23 +29,56 @@
2529
if (!($tagger instanceof Tagger))
2630
return '';
2731

32+
$target = (int) $modx->getOption('target', $scriptProperties, $modx->resource->id, true);
2833
$tagTpl = $modx->getOption('tagTpl', $scriptProperties, '');
2934
$groupTpl = $modx->getOption('groupTpl', $scriptProperties, '');
35+
$outTpl = $modx->getOption('outTpl', $scriptProperties, '');
3036
$tagSeparator = $modx->getOption('tagSeparator', $scriptProperties, '');
3137
$groupSeparator = $modx->getOption('groupSeparator', $scriptProperties, '');
3238

39+
$friendlyURL = (int) $modx->getOption('friendlyURL', $scriptProperties, $modx->getOption('friendly_urls', null, 0));
40+
$linkTagScheme = $modx->getOption('linkTagScheme', $scriptProperties, $modx->getOption('link_tag_scheme', null, -1));
41+
3342
$currentTags = $tagger->getCurrentTags();
43+
$currentTagsLink = array();
44+
45+
foreach($currentTags as $currentTag) {
46+
$currentTagsLink[$currentTag['alias']] = array_keys($currentTag['tags']);
47+
}
3448

3549
$output = array();
3650

3751
foreach ($currentTags as $currentTag) {
3852
if (!isset($currentTag['tags'])) continue;
3953

4054
$tags = array();
55+
4156
foreach ($currentTag['tags'] as $tag) {
57+
$linkData = $currentTags;
58+
unset($linkData[$currentTag['alias']]['tags'][$tag['alias']]);
59+
if (count($linkData[$currentTag['alias']]['tags']) === 0) {
60+
unset($linkData[$currentTag['alias']]);
61+
}
62+
63+
if ($friendlyURL === 1) {
64+
$linkPath = array_reduce(array_keys($linkData), function($carry, $item) use ($linkData) {
65+
return $carry . $item . '/' . implode('/', array_unique(array_keys($linkData[$item]['tags']))) . '/';
66+
}, '');
67+
68+
$uri = rtrim($modx->makeUrl($target, '', '', $linkTagScheme), '/') . '/' . $linkPath;
69+
} else {
70+
$args = [];
71+
foreach ($linkData as $group) {
72+
$args[$group['alias']] = implode(',', array_keys($group['tags']));
73+
}
74+
75+
$uri = $modx->makeUrl($target, '', $args, $linkTagScheme);
76+
}
77+
4278
$phs = array (
4379
'tag' => $tag['tag'],
4480
'alias' => $tag['alias'],
81+
'uri' => $uri,
4582
'group_name' => $currentTag['group'],
4683
'group_alias' => $currentTag['alias'],
4784
);
@@ -52,7 +89,7 @@
5289
$tags[] = $tagger->getChunk($tagTpl, $phs);
5390
}
5491
}
55-
92+
5693
$groupPhs = array(
5794
'name' => $currentTag['group'],
5895
'alias' => $currentTag['alias'],
@@ -67,4 +104,10 @@
67104
}
68105
}
69106

70-
return implode($groupSeparator, $output);
107+
if (!empty($outTpl) && !empty($output)) {
108+
return $tagger->getChunk($outTpl, array(
109+
'groups' => implode($groupSeparator, $output)
110+
));
111+
}
112+
113+
return implode($groupSeparator, $output);

Diff for: core/components/tagger/elements/snippets/taggergettags.snippet.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
$weight = (int) $modx->getOption('weight', $scriptProperties, '0');
6565

66-
$friendlyURL = $modx->getOption('friendlyURL', $scriptProperties, $modx->getOption('friendly_urls', null, 0));
66+
$friendlyURL = (int) $modx->getOption('friendlyURL', $scriptProperties, $modx->getOption('friendly_urls', null, 0));
6767
$linkTagScheme = $modx->getOption('linkTagScheme', $scriptProperties, $modx->getOption('link_tag_scheme', null, -1));
6868

6969
$sort = $modx->getOption('sort', $scriptProperties, '{}');

0 commit comments

Comments
 (0)