|
|
@@ -0,0 +1,59 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Opentalent\OtTemplating\ViewHelpers\Image;
|
|
|
+
|
|
|
+
|
|
|
+use Opentalent\OtCore\Exception\ApiRequestException;
|
|
|
+use Opentalent\OtCore\Service\OpentalentApiService;
|
|
|
+use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Returns the absolute url of the requested image
|
|
|
+ *
|
|
|
+ * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
|
|
|
+ *
|
|
|
+ * {ot:image.getByUrl(path: "/media/cache/crop_md/organization/123/upload/my_picture.jpg")}
|
|
|
+ *
|
|
|
+ * @see ot_core/Classes/Service/OpentalentImageService.php
|
|
|
+ * @package Opentalent\OtTemplating\ViewHelpers
|
|
|
+ */
|
|
|
+class GetSrcByPathViewHelper extends OtAbstractViewHelper
|
|
|
+{
|
|
|
+ public OpentalentApiService $opentalentApiService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param OpentalentApiService $opentalentApiService
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function injectOpentalentApiService(OpentalentApiService $opentalentApiService)
|
|
|
+ {
|
|
|
+ $this->opentalentApiService = $opentalentApiService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * -- This method is expected by Fluid --
|
|
|
+ * Declares the viewhelper's parameters
|
|
|
+ */
|
|
|
+ public function initializeArguments()
|
|
|
+ {
|
|
|
+ $this->registerArgument(
|
|
|
+ 'path',
|
|
|
+ 'string',
|
|
|
+ 'The path (relative url) of the image in the storage',
|
|
|
+ true
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * -- This method is expected by Fluid --
|
|
|
+ * Renders the content as html
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ * @throws ApiRequestException
|
|
|
+ */
|
|
|
+ public function render()
|
|
|
+ {
|
|
|
+ $path = $this->arguments['path'];
|
|
|
+ return $this->opentalentApiService->getApiUri($path, true);
|
|
|
+ }
|
|
|
+}
|