Elgg\EntityIconService::getIcon PHP Method

getIcon() public method

Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore
public getIcon ( ElggEntity $entity, string $size, string $type = 'icon' ) : ElggIcon
$entity ElggEntity Entity that owns the icon
$size string Size of the icon
$type string The name of the icon. e.g., 'icon', 'cover_photo'
return ElggIcon
    public function getIcon(ElggEntity $entity, $size, $type = 'icon')
    {
        $size = elgg_strtolower($size);
        $params = ['entity' => $entity, 'size' => $size, 'type' => $type];
        $entity_type = $entity->getType();
        $default_icon = new ElggIcon();
        $default_icon->owner_guid = $entity->guid;
        $default_icon->setFilename("icons/{$type}/{$size}.jpg");
        $icon = $this->hooks->trigger("entity:{$type}:file", $entity_type, $params, $default_icon);
        if (!$icon instanceof ElggIcon) {
            throw new InvalidParameterException("'entity:{$type}:file', {$entity_type} hook must return an instance of ElggIcon");
        }
        return $icon;
    }