Skip to content

Commit

Permalink
ObjectsRendererHook: Allow method createObjectLink() to return null
Browse files Browse the repository at this point in the history
Because even if the hook(source) implementation is present, it is possible that
the it cannot find a result for the given object (object is deleted/changed).
  • Loading branch information
sukhwinder33445 committed May 31, 2024
1 parent 1252985 commit b366cd6
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions library/Notifications/Hook/ObjectsRendererHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ abstract public function getSourceType(): string;
*
* @param array<string, string> $objectIdTag
*
* @return ValidHtml
* @return ?ValidHtml Returns null if no object with given tag found
*/
abstract public function createObjectLink(array $objectIdTag): ValidHtml;
abstract public function createObjectLink(array $objectIdTag): ?ValidHtml;

/**
* Register object ID tags to the cache
Expand Down Expand Up @@ -277,13 +277,17 @@ final public static function renderObjectLink(Objects $object): ?ValidHtml
try {
$sourceType = $hook->getSourceType();
if ($object->source->type === $sourceType) {
return $hook->createObjectLink($object->id_tags)
->addAttributes([
'class' => [
'icinga-module',
'module-' . ($sourceType === 'icinga2' ? 'icingadb' : $sourceType)
]
]);
$objectLink = $hook->createObjectLink($object->id_tags);
if ($objectLink === null) {
break;
}

return $objectLink->addAttributes([
'class' => [
'icinga-module',
'module-' . ($sourceType === 'icinga2' ? 'icingadb' : $sourceType)
]
]);
}
} catch (Exception $e) {
Logger::error('Failed to load hook %s:', get_class($hook), $e);
Expand Down

0 comments on commit b366cd6

Please sign in to comment.