Elgg  Version 6.1
default.php
Go to the documentation of this file.
1 <?php
13 $entity = elgg_extract('entity', $vars);
14 if (!$entity instanceof ElggEntity) {
15  return;
16 }
17 
19 // Get size
20 $size = elgg_extract('size', $vars, 'medium');
21 if (!array_key_exists($size, $icon_sizes)) {
22  $size = 'medium';
23 }
24 
25 $vars['size'] = $size;
26 
27 $img_class = elgg_extract_class($vars, [], 'img_class');
28 
29 $title = htmlspecialchars($entity->getDisplayName() ?? '', ENT_QUOTES, 'UTF-8', false);
30 
31 $url = false;
32 if (elgg_extract('use_link', $vars, true)) {
33  $url = elgg_extract('href', $vars, $entity->getURL());
34 }
35 
36 if (!isset($vars['width'])) {
37  $vars['width'] = $size != 'master' ? $icon_sizes[$size]['w'] : null;
38 }
39 
40 if (!isset($vars['height'])) {
41  $vars['height'] = $size != 'master' ? $icon_sizes[$size]['h'] : null;
42 }
43 
45  'src' => $entity->getIconURL($size),
46  'alt' => $title,
47 ];
48 
49 if (!empty($img_class)) {
50  $img_params['class'] = $img_class;
51 }
52 
53 if (!empty($vars['width'])) {
54  $img_params['width'] = elgg_extract('width', $vars);
55 }
56 
57 if (!empty($vars['height'])) {
58  $img_params['height'] = elgg_extract('height', $vars);
59 }
60 
61 $img = elgg_view('output/img', $img_params);
62 if (empty($img)) {
63  return;
64 }
65 
66 if ($url) {
67  $params = [
68  'href' => $url,
69  'text' => $img,
70  'title' => $entity->getDisplayName(),
71  'is_trusted' => true,
72  ];
73  $link_class = elgg_extract_class($vars, [], 'link_class');
74  if (!empty($link_class)) {
75  $params['class'] = $link_class;
76  }
77 
78  echo elgg_view('output/url', $params);
79 } else {
80  echo $img;
81 }
elgg_get_icon_sizes(string $entity_type=null, string $entity_subtype=null, $type= 'icon')
Returns a configuration array of icon sizes.
if(elgg_extract('use_link', $vars, true)) if(!isset($vars['width'])) if(!isset($vars['height'])) $img_params
Definition: default.php:44
if(elgg_extract('use_link', $vars, true)) if(!isset($vars['width'])) if(!isset($vars['height'])) if(!empty($img_class)) if(!empty($vars['width'])) if(!empty($vars['height'])) $img
Definition: default.php:61
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:256
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
$url
Definition: default.php:31
if(!array_key_exists($size, $icon_sizes)) $vars['size']
Definition: default.php:25
if(!$entity instanceof ElggEntity) $icon_sizes
Definition: default.php:18
$img_class
Definition: default.php:27
$size
Definition: default.php:20
$entity
Generic icon view.
Definition: default.php:13
$title
Definition: default.php:29
$params
Definition: default.php:50
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:279