Elgg  Version 4.3
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 $vars['size'] = $size;
25 
26 $img_class = elgg_extract_class($vars, [], 'img_class');
27 
28 $title = htmlspecialchars($entity->getDisplayName() ?? '', ENT_QUOTES, 'UTF-8', false);
29 
30 $url = false;
31 if (elgg_extract('use_link', $vars, true)) {
32  $url = elgg_extract('href', $vars, $entity->getURL());
33 }
34 
35 if (!isset($vars['width'])) {
36  $vars['width'] = $size != 'master' ? $icon_sizes[$size]['w'] : null;
37 }
38 if (!isset($vars['height'])) {
39  $vars['height'] = $size != 'master' ? $icon_sizes[$size]['h'] : null;
40 }
41 
43  'src' => $entity->getIconURL($size),
44  'alt' => $title,
45 ];
46 
47 if (!empty($img_class)) {
48  $img_params['class'] = $img_class;
49 }
50 
51 if (!empty($vars['width'])) {
52  $img_params['width'] = elgg_extract('width', $vars);
53 }
54 
55 if (!empty($vars['height'])) {
56  $img_params['height'] = elgg_extract('height', $vars);
57 }
58 
59 $img = elgg_view('output/img', $img_params);
60 if (empty($img)) {
61  return;
62 }
63 
64 if ($url) {
65  $params = [
66  'href' => $url,
67  'text' => $img,
68  'is_trusted' => true,
69  ];
70  $link_class = elgg_extract_class($vars, [], 'link_class');
71  if ($link_class) {
72  $params['class'] = $link_class;
73  }
74 
75  echo elgg_view('output/url', $params);
76 } else {
77  echo $img;
78 }
if(elgg_extract('use_link', $vars, true)) if(!isset($vars['width'])) if(!isset($vars['height'])) $img_params
Definition: default.php:42
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:59
elgg_get_icon_sizes($entity_type=null, $entity_subtype=null, $type= 'icon')
Returns a configuration array of icon sizes.
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:569
$url
Definition: default.php:30
if(!array_key_exists($size, $icon_sizes)) $vars['size']
Definition: default.php:24
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:547
if(!$entity instanceof ElggEntity) $icon_sizes
Definition: default.php:18
$img_class
Definition: default.php:26
$size
Definition: default.php:20
$entity
Generic icon view.
Definition: default.php:13
$title
Definition: default.php:28
$params
Definition: default.php:50
elgg echo
Translates a string.
Definition: deprecated.js:530
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:179