Elgg  Version master
tags.php
Go to the documentation of this file.
1 <?php
2 
16 if (isset($vars['entity'])) {
17  $vars['tags'] = elgg_extract('entity', $vars)->tags;
18  unset($vars['entity']);
19 }
20 
22 unset($vars['value']);
23 if (empty($vars['tags']) && (!empty($value) || $value === 0 || $value === '0')) {
24  $vars['tags'] = $value;
25 }
26 
27 if (empty($vars['tags']) && $value !== 0 && $value !== '0') {
28  return;
29 }
30 
32 unset($vars['tags']);
33 
34 if (!is_array($tags)) {
35  $tags = [$tags];
36 }
37 
38 $list_class = elgg_extract_class($vars, 'elgg-tags', 'list_class');
39 unset($vars['list_class']);
40 
41 $item_class = elgg_extract_class($vars, 'elgg-tag', 'item_class');
42 unset($vars['item_class']);
43 
44 $icon_name = elgg_extract('icon', $vars, 'tag');
45 unset($vars['icon']);
46 
47 $icon_class = elgg_extract_class($vars, [], 'icon_class');
48 unset($vars['icon_class']);
49 
50 if ($icon_name === false) {
51  $icon = '';
52 } else {
53  $icon = elgg_view_icon($icon_name, ['class' => $icon_class]);
54 }
55 
56 $separator = elgg_extract('separator', $vars, ', ');
57 unset($vars['separator']);
58 
60 
62 foreach ($tags as $tag) {
63  if (is_scalar($tag) && elgg_strlen($tag) > 0) {
64  $params['value'] = $tag;
65  $tag_view = elgg_view('output/tag', $params);
66  $list_items[] = elgg_format_element('span', ['class' => $item_class], $tag_view);
67  }
68 }
69 
70 if (empty($list_items)) {
71  return;
72 }
73 
74 echo elgg_format_element('div', ['class' => $list_class], $icon . implode($separator, $list_items));
if(!is_string($title)||$title=== '') $tag
Definition: title.php:15
elgg_strlen()
Wrapper function for mb_strlen().
Definition: mb_wrapper.php:53
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
$list_items
Definition: tags.php:59
$separator
Definition: tags.php:56
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
if(function_exists('apache_get_version')) $icon
Definition: generic.php:49
$item_class
Definition: tags.php:41
$vars['class']
Elgg tag input Displays a tag input field.
Definition: tags.php:12
if(isset($vars['entity'])) $value
Elgg tags Tags can be a single string (for one tag) or an array of strings.
Definition: tags.php:21
elgg_view_icon(string $name, array $vars=[])
View an icon glyph.
Definition: views.php:1261
$params
Definition: tags.php:61
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
elgg_extract_class(array $array, array|string $existing=[], string $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:277
if(!is_array($tags)) $list_class
Definition: tags.php:38
$tags
Output object tags.
Definition: tags.php:9
$icon_name
Definition: tags.php:44
$icon_class
Definition: tags.php:47