|
|
@@ -3,6 +3,7 @@
|
|
|
namespace Opentalent\OtTemplating\ViewHelpers\Image;
|
|
|
|
|
|
|
|
|
+use Opentalent\OtCore\Exception\ApiRequestException;
|
|
|
use Opentalent\OtCore\Service\OpentalentImageService;
|
|
|
use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
|
|
|
|
|
|
@@ -48,6 +49,13 @@ class GetSrcByIdViewHelper extends OtAbstractViewHelper
|
|
|
false,
|
|
|
'md'
|
|
|
);
|
|
|
+ $this->registerArgument(
|
|
|
+ 'default',
|
|
|
+ 'string',
|
|
|
+ 'The src of the image if the file is not found',
|
|
|
+ false,
|
|
|
+ ''
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -59,7 +67,15 @@ class GetSrcByIdViewHelper extends OtAbstractViewHelper
|
|
|
public function render() {
|
|
|
$fileId = $this->arguments['fileId'];
|
|
|
$size = $this->arguments['size'];
|
|
|
- return $this->opentalentImageService->getImageUrl($fileId, $size);
|
|
|
+ $default = $this->arguments['default'];
|
|
|
+
|
|
|
+ try {
|
|
|
+ return $this->opentalentImageService->getImageUrl($fileId, $size);
|
|
|
+ } catch (ApiRequestException $e) {
|
|
|
+ if ($e->getCode() === 404) {
|
|
|
+ return $default;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|