Skip to content

Commit

Permalink
fix(views): output/tag shows text if there is no href present
Browse files Browse the repository at this point in the history
fixes #7163
  • Loading branch information
jdalsem committed Mar 22, 2017
1 parent a51796a commit e7dfa2a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
33 changes: 33 additions & 0 deletions mod/search/start.php
Expand Up @@ -32,6 +32,8 @@ function search_init() {
elgg_extend_view('page/elements/sidebar', 'search/header', 0);

elgg_register_plugin_hook_handler('robots.txt', 'site', 'search_exclude_robots');

elgg_register_plugin_hook_handler('view_vars', 'output/tag', 'search_output_tag');
}

/**
Expand Down Expand Up @@ -459,3 +461,34 @@ function search_exclude_robots($hook, $type, $text) {

return $text;
}

/**
* Adds search 'href' to output/tag view vars
*
* @param \Elgg\Hook $hook Hook
* @return array
*/
function search_output_tag(\Elgg\Hook $hook) {
$vars = $hook->getValue();
if (isset($vars['href'])) {
// leave unaltered
return;
}

$query_params = [
'q' => elgg_extract('value', $vars),
'search_type' => 'tags',
'type' => elgg_extract('type', $vars, null, false),
'subtype' => elgg_extract('subtype', $vars, null, false),
];

$url = elgg_extract('base_url', $vars, 'search');

unset($vars['base_url']);
unset($vars['type']);
unset($vars['subtype']);

$vars['href'] = elgg_http_add_url_query_elements($url, $query_params);

return $vars;
}
47 changes: 14 additions & 33 deletions views/default/output/tag.php
Expand Up @@ -2,44 +2,25 @@
/**
* Elgg single tag output. Accepts all output/url options
*
* @uses $vars['value'] String
* @uses $vars['type'] The entity type, optional
* @uses $vars['subtype'] The entity subtype, optional
* @uses $vars['base_url'] Base URL for tag link, optional, defaults to search URL
* @uses $vars['value'] String, text of the tag
* @uses $vars['base_url'] Base URL for tag link, optional, usable in view var hooks
* @uses $vars['href'] URL for tag link, optional, if left empty only text is shown
*
*/

if (empty($vars['value']) && $vars['value'] !== 0 && $vars['value'] !== '0') {
$value = elgg_extract('value', $vars);
if (empty($value) && $value !== 0 && $value !== '0') {
return;
}

$query_params = [];
$href = elgg_extract('href', $vars);
$vars['rel'] = 'tag';

$query_params["q"] = $vars['value'];
$query_params["search_type"] = "tags";

if (!empty($vars['type'])) {
$query_params["type"] = $vars['type'];
unset($vars['type']);
}

if (!empty($vars['subtype'])) {
$query_params["subtype"] = $vars['subtype'];
unset($vars['subtype']);
if ($href) {
$vars['text'] = $value;
$vars['encode_text'] = true;

echo elgg_view('output/url', $vars);
} else {
echo elgg_view('output/text', $vars);
}

$url = !empty($vars['base_url']) ? $vars['base_url'] : 'search';
unset($vars['base_url']);

$url .= '?' . http_build_query($query_params);

$params = [
'href' => $url,
'text' => $vars['value'],
'encode_text' => true,
'rel' => 'tag',
];

$params = $params + $vars;

echo elgg_view('output/url', $params);

0 comments on commit e7dfa2a

Please sign in to comment.