From 034052cf4bb1df2959c3493b05defac45daed493 Mon Sep 17 00:00:00 2001 From: acognet Date: Wed, 18 Aug 2021 09:25:40 +0200 Subject: [PATCH] avoid 404 error when loading image in autocomplete --- application/utils.inc.php | 2 +- pages/ajax.render.php | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/application/utils.inc.php b/application/utils.inc.php index 1c45e7121..a7d6aee13 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -2656,7 +2656,7 @@ class utils $sMentionItemUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=details&class='.$sMentionClass.'&id={id}'; $sMentionItemPictureTemplate = (empty(MetaModel::GetImageAttributeCode($sMentionClass))) ? '' : <<{initials} +{initials} HTML; $sMentionItemTemplate = <<{$sMentionItemPictureTemplate}{friendlyname} diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 94d6ca570..92c1911bd 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -2720,10 +2720,9 @@ EOF $sObjectClass = get_class($oObject); $iObjectId = $oObject->GetKey(); $aMatch = [ - 'class' => $sObjectClass, - 'id' => $iObjectId, + 'class' => $sObjectClass, + 'id' => $iObjectId, 'friendlyname' => $oObject->Get('friendlyname'), - 'initials' => '', ]; // Try to retrieve image for contact @@ -2731,13 +2730,15 @@ EOF /** @var \ormDocument $oImage */ $oImage = $oObject->Get($sObjectImageAttCode); if (!$oImage->IsEmpty()) { - $aMatch['picture_url'] = $oImage->GetDisplayURL($sObjectClass, $iObjectId, $sObjectImageAttCode); + $aMatch['picture_style'] = "background-image: url('".$oImage->GetDisplayURL($sObjectClass, $iObjectId, $sObjectImageAttCode)."')"; + $aMatch['initials'] = ''; + } else { + // If no image found, fallback on initials + $aMatch['picture_style'] = ''; + $aMatch['initials'] = utils::ToAcronym($oObject->Get('friendlyname')); } } - // If no image found, fallback on initials - $aMatch['initials'] = array_key_exists('picture_url', $aMatch) ? '' : utils::ToAcronym($oObject->Get('friendlyname')); - $aMatches[] = $aMatch; } }