mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°2847 - Fix crash when object with state attribute has no state defined
This commit is contained in:
@@ -53,11 +53,15 @@ class TitleFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (MetaModel::HasStateAttributeCode($sObjClass)) {
|
if (MetaModel::HasStateAttributeCode($sObjClass)) {
|
||||||
$sStatusAttCode = MetaModel::GetStateAttributeCode($sObjClass);
|
|
||||||
$sStateCode = $oObject->GetState();
|
$sStateCode = $oObject->GetState();
|
||||||
$sStatusLabel = $oObject->GetStateLabel();
|
|
||||||
$sStatusColor = UIHelper::GetColorFromStatus(get_class($oObject), $sStateCode);
|
// Protection against classes with no default state (in which case we don't display the status)
|
||||||
$oTitle->SetStatus($sStatusAttCode, $sStatusLabel, $sStatusColor);
|
if(!empty($sStateCode)) {
|
||||||
|
$sStatusAttCode = MetaModel::GetStateAttributeCode($sObjClass);
|
||||||
|
$sStatusLabel = $oObject->GetStateLabel();
|
||||||
|
$sStatusColor = UIHelper::GetColorFromStatus(get_class($oObject), $sStateCode);
|
||||||
|
$oTitle->SetStatus($sStatusAttCode, $sStatusLabel, $sStatusColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $oTitle;
|
return $oTitle;
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ namespace Combodo\iTop\Application\UI\Helper;
|
|||||||
|
|
||||||
use MetaModel;
|
use MetaModel;
|
||||||
|
|
||||||
|
// TODO 3.0.0: Delete this class as it is only a temporary helper while code is being reworked.
|
||||||
class UIHelper
|
class UIHelper
|
||||||
{
|
{
|
||||||
public static function GetColorFromStatus(string $sClass, string $sStateCode)
|
public static function GetColorFromStatus(string $sClass, ?string $sStateCode): string
|
||||||
{
|
{
|
||||||
$sStatusColor = 'neutral';
|
|
||||||
$sRootClass = MetaModel::GetRootClass($sClass);
|
$sRootClass = MetaModel::GetRootClass($sClass);
|
||||||
switch ($sRootClass) {
|
switch ($sRootClass) {
|
||||||
case 'Ticket':
|
case 'Ticket':
|
||||||
|
|||||||
Reference in New Issue
Block a user